Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/vue.js/6.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Vue.js Vue.http.interceptors.push undefined不是对象_Vue.js_Vuejs2 - Fatal编程技术网

Vue.js Vue.http.interceptors.push undefined不是对象

Vue.js Vue.http.interceptors.push undefined不是对象,vue.js,vuejs2,Vue.js,Vuejs2,当服务器在我的Vue应用程序中返回错误401时,我想注销并重定向到登录页面,但在我的控制台中,我看到错误:无法读取未定义的属性“interceptors”。你知道怎么解决吗 import router from './router/router.js' import Vue from 'vue' import BootstrapVue from 'bootstrap-vue' import Vuelidate from 'vuelidate' Vue.use(BootstrapVue) Vu

当服务器在我的Vue应用程序中返回错误401时,我想注销并重定向到登录页面,但在我的控制台中,我看到错误:无法读取未定义的属性“interceptors”。你知道怎么解决吗

import router from './router/router.js'
import Vue from 'vue'
import BootstrapVue from 'bootstrap-vue'
import Vuelidate from 'vuelidate'


Vue.use(BootstrapVue)
Vue.use(Vuelidate)

Vue.http.interceptors.push(function (request, next) {
    next(function (response) {
      if (response.status === 401) {
        let msg = response.body.returnMessage
        localStorage.setItem('logoutReason', msg)
      }
    })
  })

const app = new Vue({
    el: '#app',
    router
});

根据他的建议,您应该首先将vue资源作为依赖项安装,然后将其用作从“vue资源”导入VueResource;&Vue.usevuersource

非常感谢,现在一切都很好;