I've integrated vue-reactive-storage to have a reactive alternative to localStorage in my Vue application. This plugin creates a vue object that is accessible to all components. I'm facing an issue when trying to access this object within my axios interceptors response function, as I keep getting the error message
TypeError: Cannot read property 'localStorage' of undefined
.
Here's a snippet from my app.js:
require('./bootstrap');
import Vue from 'vue';
import Vuetify from 'vuetify';
import reactiveStorage from "vue-reactive-storage";
import store from './store/index';
Vue.use(Vuetify);
Vue.use(reactiveStorage, {
"snackBar": {show: false, text: '(Initial snackbar text.)', type: 'info', timedelay: 2000},
});
axios.interceptors.response.use(response => response, error => {
this.localStorage.snackBar.text = error.response.data.message || 'Request error status: ' + error.response.status,
this.localStorage.snackBar.type = 'error'
this.localStorage.snackBar.show = 'true'
})
import router from './routes';
const app = new Vue({
el: '#app',
vuetify: new Vuetify(),
router,
store,
}
});
Is there a way around this issue?
This setup is on Laravel v6.4.1 and Vue v2.6.10.