扫码关注官方订阅号
我在methods里面 使用this.axios说未定义,但是我在main.js里面已经
import axios from 'axios' Vue.use(axios)
请问一下是怎么回事?
光阴似箭催人老,日月如移越少年。
axios 并不属于 Vue 的插件。框架与 HTTP 库本身没有必然的归属性关系,只要实现了 HTTP 标准,都可以在任意框架中使用。
想要用 this 调用的话,可以绑定到 Vue.prototype 上。
Vue.prototype
尤大原话:https://github.com/vuefe/vuef...
Vue.prototype.$ajax = axios;
在methodsthis.$ajax();
可以这样写。import Vue from 'vue';import axios from 'axios';Vue.prototype.$http = axios;
然后用的是时候就是 this.$http.get() ...
楼主,要想用this.xx的方法调用,把axios绑定到Vue.prototype.$http上就可以了!
Vue.prototype.$http = Axios // 类似于vue-resource的调用方法,之后可以在实例里直接用this.$http.get()等
微信扫码关注PHP中文网服务号
QQ扫码加入技术交流群
Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号
PHP学习
技术支持
返回顶部
axios 并不属于 Vue 的插件。
框架与 HTTP 库本身没有必然的归属性关系,只要实现了 HTTP 标准,都可以在任意框架中使用。
想要用 this 调用的话,可以绑定到
Vue.prototype上。尤大原话:https://github.com/vuefe/vuef...
Vue.prototype.$ajax = axios;
在methods
this.$ajax();
可以这样写。
import Vue from 'vue';
import axios from 'axios';
Vue.prototype.$http = axios;
然后用的是时候就是 this.$http.get() ...
楼主,要想用this.xx的方法调用,把axios绑定到Vue.prototype.$http上就可以了!