【发布时间】:2018-05-29 07:29:13
【问题描述】:
如何通过我的应用使 axios 的 API 请求可重用, 这样我就可以避免一遍又一遍地编写相同的代码..
//load the axios HTTP library
window.axios = require('axios');
window.Vue = require('vue');
const app = new Vue({
el: '#app',
mounted(){
console.log('hello!');
}
});
我正在考虑尝试这样的事情 ( gist ) 但我不知道如何将函数附加到 Vue 实例 并从vue-components 直接 ..
【问题讨论】:
-
我已经构建了axios-resource,它可以帮助使用简单的 API 封装常见调用。