Reputation: 671
i am using this code in router index.js for login route in Vuejs
if (this.$cookie.get('token')) {
next('/dashboard')
}
But i am getting get is undefined
Upvotes: 1
Views: 6556
Reputation: 21
I just spent quite a bit of time with this. In entry:
import VueCookies from 'vue-cookies'
Vue.use(VueCookies)
Inside a Vue component:
console.log(this.$cookies);
this.$cookies.set('test1', 'content');
console.log(this.$cookies.keys());
console.log(this.$cookies.get('test1'));
The $cookies
object was defined with all the correct functions, but keys()
was returning an empty array and get('test1')
was returning null
.
Turns out, Google Chrome doesn't support cookies for local files. Try using a different browser.
There used to be a command-line flag to allow cookies for local files, but it seems to be have been removed.
Upvotes: 2