如何吧vue-resource 再次封装到一个js文件里面 如:
let Ajax = { Vue.http.get(url,data).then( // ...代码 return data ) }
然后在别的地方直接调用 如:
save(){ this.Ajax.get(url,data); }
// api.js export default { save (params = {}) { return Vue.http.get(url, { params }).then(res => { // some handling return res.data }) }, // ... }
然后在其它文件中引入使用即可
import api from './api' api.save({ // params... }).then(data => { // ... })
用 axios 吧,官方已不推荐使用 vue-resource 了,使用 axios 配合 vue-axios 使用
axios
vue-resource
vue-axios
全局注册个插件
https://vuefe.cn/v2/guide/plu...
export default { install: function() { Vue.prototype.$ajax = Ajax; } }
然后use该文件,接着就可以使用啦
然后在其它文件中引入使用即可
用
axios
吧,官方已不推荐使用vue-resource
了,使用 axios 配合vue-axios
使用全局注册个插件
https://vuefe.cn/v2/guide/plu...
然后use该文件,接着就可以使用啦