84669 person learning
152542 person learning
20005 person learning
5487 person learning
7821 person learning
359900 person learning
3350 person learning
180660 person learning
48569 person learning
18603 person learning
40936 person learning
1549 person learning
1183 person learning
32909 person learning
How about encapsulating vue-resource into a js file again, such as:
let Ajax = { Vue.http.get(url,data).then( // ...代码 return data ) }
Then call it directly elsewhere, such as:
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 }) }, // ... }
Then just import and use it in other files
import api from './api' api.save({ // params... }).then(data => { // ... })
Use axios. Officially, it is no longer recommended to use vue-resource. Use axios together with vue-axios to use
axios
vue-resource
vue-axios
Register a plugin globally
https://vuefe.cn/v2/guide/plu...
export default { install: function() { Vue.prototype.$ajax = Ajax; } }
Then use the file and you can use it
Then just import and use it in other files
Use
axios
. Officially, it is no longer recommended to usevue-resource
. Use axios together withvue-axios
to useRegister a plugin globally
https://vuefe.cn/v2/guide/plu...
Then use the file and you can use it