alfhen / vue-cookie

A Vue.js plugin for manipulating cookies
MIT License
821 stars 72 forks source link

How to use this plugin by 'Vue.cookie' #28

Closed StrangeTown closed 7 years ago

StrangeTown commented 7 years ago

I want to set a cookie in vuex's mutations.js file,

but when I use 'Vue.cookie' directly, there was an error occurred:

TypeError: WEBPACK_IMPORTED_MODULE_0_vue.default.cookie is not a function

StrangeTown commented 7 years ago

It was my fault, I just used it as "Vue.cookie(name, value)".

The right way to use it is Vue.cookie.set(name, value)

ghost commented 6 years ago

@StrangeTown I'm also looking to get this to work within my STORE. Do I just import it within /store/index.js file?

import Vue from 'vue'
import axios from 'axios'
import Vuex from 'vuex'
import cookie from 'vue-cookie'

I have something like:

mutations: {

        setCookie(value) {
            Vue.cookie.set('lang', value)
        }

    },

    actions: {
        async nuxtServerInit({ state, commit }, { isDev }) {

            if (Vue.cookie.get() == null) {
                console.log('No cookies. Let\'s set one up');
                commit('setCookie', state.apiURI)
            }

I get error: document is not defined