Reputation: 105
I want do logouts and redirect to login page when server return error 401 in my Vue app but in my console I see error: "Cannot read property 'interceptors' of undefined". Have you any idea how fix that?
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
});
Upvotes: 0
Views: 416
Reputation: 2761
According his documentation you should first install vue-resourse
as dependency then use it as import VueResource from 'vue-resource';
& Vue.use(VueResource);
Upvotes: 1