-
Notifications
You must be signed in to change notification settings - Fork 121
Using axios? #39
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
Hi, you have to create typings file for axios plugin, for example: ClientApp/src/plugins/axios.d.ts import { AxiosStatic } from "axios";
declare module "vue/types/vue" {
interface Vue {
axios: AxiosStatic;
}
interface VueConstructor {
axios: AxiosStatic;
}
} Then Vue components can access registered plugin instance |
Thank you. Should the Forecast page get updated then or? |
I will update it later, in this case I will try to update also plugin registration from js to ts file and create typings declaration for the registration function. |
Also interested in how to use the axios plugin properly. I can import it in a Vue component that uses javascript with I also tried creating the |
UP.
|
@liborpansky what about using axios within the vuex store? Currently in the code there is the Using |
You're right, the plugin instance is not accessible in the vuex store. You can import direct axios instance in store, but in this way you would miss any logic you applied in request / response interceptors... There's a dirty workaround to pass your Vue instance as an action parameter, so you can access any plugin registered, but it's not an elegant solution I would choose. Generally I end up with a sort of API Service class responsible for API calls, which uses directly axios non plugin instance that is being imported to all store modules and components directly to encapsulate http calls. |
Thanks I will look into that |
I think, what using axios in "store" layer is not better idea for architecture. Maybe i'm wrong :) |
There is a plugin that registers an axios instance but
import axios from "axios"
The text was updated successfully, but these errors were encountered: