如何在 vue-resource 全局拦截器中访问vue实例

  1. 项目结构:

    main.js 
    app.vue
    home.vue
  2. 我在main.js里写http拦截器, 然后根据 response 判断登录状态, 登录失效我想使用全局的弹窗提示重新登录, 全局提示采用 element 的 $message, 请问如何调用.

  3. Vue.http.interceptors.push((request, next) => {
        next((response) => {
            //if 登录失效, 
            //Vue.$message('请重新登录');
        }
    }
阅读 5.8k
2 个回答
新手上路,请多包涵

Vue.http.interceptors.push((request, next) => {

next((response) => {
    //if 登录失效, 
    //Vue.$message('请重新登录');
}

}
改为如下,必须加上.prototype:
Vue.http.interceptors.push((request, next) => {

next((response) => {
    //if 登录失效, 
    //Vue.prototype.$message('请重新登录');
}

}

撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进
推荐问题