Open antonyhaman opened 4 years ago
@kotvertolet did you find any solutions ?
@kotvertolet did you find any solutions ?
Use Vue.cookie.get('token') instead
Vuex doesn't reference the vue instance, to use the instance in vuex you have to use this._vm
, so it should work like:
const state = {
token: this._vm.$cookie.get('token') || "",
...
};
I hope this helps you
If you have declared your import like this
import VueCookie from 'vue-cookie' Vue.use(VueCookie)
you can refer to the global variable with "VueCookie.set()" from anywhere. Even in the Vuex store.
Hi there! I'm totally new with Vue and front-end in general (I'm backend java developer :smile:) therefore I might ask dumb questions, but I'm trying to build a simple Vue app with Vuex and cookie as security token. What I'm currently have: main.js:
auth.js:
When I run my app I get 'Cannot read property '$cookie' of undefined' at
Vue.prototype.$cookie.get('token')
line. What I'm doint wrong?