一路繁花似锦绣前程
失败的越多,成功才越有价值

导航

 
1、npm i -S cookie-universal-nuxt
2、nuxt.config.js
    modules: [
        'cookie-universal-nuxt'
    ]
3、使用
    * 服务端(store/index.js)
        const actions = {
            // nuxt提供的,每次刷新页面都会执行此函数,参数1为store,参数2为context。(只能在index.js中)
            nuxtServerInit({commit}, {app}) {
                app.$cookies.get('key')
            }
        }
    * 客户端
        mounted() {
            this.$cookies.set('key', 'value', {
                maxAge: 60 * 60 * 24 * 7  // 单位秒
            })
        }

 

posted on 2021-03-25 13:09  一路繁花似锦绣前程  阅读(427)  评论(0编辑  收藏  举报