vue拦截器Vue.http.interceptors.push
刚开始学vue,github上down了一个开源项目,看源代码的时候看到了这个地方: /** * @export * @param {any} request * @param {any} next * @returns */ import store from './vuex/store' // 全局错误处理,全局loading import { setLoading, setTip } from './vuex/actions/doc_actions' export default function (request, next) { if (request.tip !== false) { setLoading(store, true) } next((res) => { setLoading(store, false) let data = JSON.parse(res.data) if (res.status === 0) { setTip(store, { text: '网络不给力,请稍后再试' }) } if (!data.success) { setTip(store, { text: data.error_msg }) } }) } 这是一个全局的拦截器。于是搜索vue拦截器的用法,下面这一篇写的不错: http://www.cnblogs.com/dupd/p