I'm a selftaught (web) developer. On sunny days, you can find me hiking through the Teutoburg Forest, on rainy days coding or with a good fiction novel in hand.
I'm not sure if I got your question right. Axios is an http client, which represents the business logic of sending requests to - and receiving responses from your backend. You might add it as part of a component. I don't think it makes sense to use it as such standalone.
Perhaps you're striding to create an axios instance, which you can then require as a mixin for one or more components. Or add it directly to it as a method.
I'm a selftaught (web) developer. On sunny days, you can find me hiking through the Teutoburg Forest, on rainy days coding or with a good fiction novel in hand.
Then try the following, given you have axios installed
Add a folder called 'mixins' to your project
Create a new file called myAxios.js inside of it
Add the following code to it:
importaxiosfrom'axios';// Replace the baseUrl with your backend root pathconstmyAxios=axios.create({baseUrl:'http://localhost:3000/api',timeout:1000,headers:{},});exportdefaultmyAxios;
Then, in the component in which you'd like to use the instance:
Import the 'myAxios' instance
Use the normal http methods to target your api's endpoints
If you need customized options, you can add them here as well, they'll be merged with the ones of the instance
// On top of your componentimportappInstancefrom'@/mixins/myAxios.js';// Inside your component's methods. Replace /endpoint with your path:appInstance.get('/endpoint').then(response=>console.log(response.data))
I've only tried this in Vue and Vanilla, in React it cannot be too different though :)
For further actions, you may consider blocking this person and/or reporting abuse
We're a place where coders share, stay up-to-date and grow their careers.
I'm not sure if I got your question right. Axios is an http client, which represents the business logic of sending requests to - and receiving responses from your backend. You might add it as part of a component. I don't think it makes sense to use it as such standalone.
Perhaps you're striding to create an axios instance, which you can then require as a mixin for one or more components. Or add it directly to it as a method.
I mean that as in to use it, like a JS file of Info.js and SetInfo.js
Then try the following, given you have axios installed
Then, in the component in which you'd like to use the instance:
I've only tried this in Vue and Vanilla, in React it cannot be too different though :)