Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Vue-Cookies: this.$cookies is undefined

Tags:

cookies

vue.js

In my main component I have:

mounted() {
    window.$cookie.set('cookie_name', userName, expiringTime);
},

This yields the following error:

Error in mounted hook: "TypeError: Cannot read property 'set' of undefined"

In my main.js I have:

import VueCookies from 'vue-cookies';
Vue.use(VueCookies);

Any idea?

like image 718
drake035 Avatar asked Nov 20 '18 12:11

drake035


1 Answers

You must use window.$cookies or this.$cookies (don't forget the s).

like image 152
Multicolaure Avatar answered Oct 23 '22 04:10

Multicolaure