[vue warn]: inject() can only be used inside setup()

Problem background: Recently when I was using vue3 to write the login function of the management system, a warning appeared on the browser console after encapsulating axios: [Vue warn]: inject() can only be used inside setup() or functional components.

Reason: Because useRouter and useStore must be introduced in setup in vue3, we cannot directly introduce them in the encapsulated axios file.

1.bug tips:

 2. Then we change router and store to be imported from @router,@store, as shown below:

 Finally, I hope my method can give you some help.

 

Guess you like

Origin blog.csdn.net/m0_51749295/article/details/129162910