VUE的ajax拦截器
先介紹第一種? 基于餓了么組件中的全局ajax請求等待的書寫方法
main.js中
import EventBus from './../src/core/EventBus';
Vue.use(EventBus);
Vue.http.interceptors.push((request, next) => {
// before sending request
EventBus.$emit('toggleLoading')
next((response => {
// after sending request
EventBus.$emit('toggleLoadingEnd')
}));
});
eventBus文件
import Vue from 'vue';
const EventBus = new Vue();
export default EventBus;
Vue文件中
import EventBus from './../core/EventBus’;
mounted() {
console.log("加載完成App.vue");
EventBus.$on('toggleLoading', () => {
this.$loading({ fullscreen: true })
});
EventBus.$on('toggleLoadingEnd', () => {
this.$loading({ fullscreen: true }).close();
});
}
《新程序員》:云原生和全面數字化實踐50位技術專家共同創作,文字、視頻、音頻交互閱讀總結
以上是生活随笔為你收集整理的VUE的ajax拦截器的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: Tools - 一些代码阅读的方法
- 下一篇: idea开发vue