Vue项目使用axios

Vue插件使用

通过全局方法 Vue.use(plugin) 使用插件

    import Vue from 'vue';
    import VueRouter from 'vue-router';
    Vue.use(VueRouter);

axios在Vue中的使用

axios通过Vue.use无法实现全局插件的挂载

    import axios from 'axios';
    Vue.use(axios);// TypeError

axios需要挂载在Vue.prototype上,就可以实现全局变量的挂载了

    import axios from 'axios';
    Vue.prototype.$axios = axios;
    //Vue实例中可以通过this.$axios进行调用
    this.$axios(url,options);

猜你喜欢

转载自blog.csdn.net/hh921227/article/details/80320156