1.安装vue-cookies
npm install vue-cookies --save
2.引入vue-cookies 安装完毕后,我们需要在vue项目的main.js中明确引入vue-cookies。
import Vue from 'vue'
import VueCookies from 'vue-cookies'
Vue.use(VueCookies)
//设置全局配置,设置cookie过期时间
// default: expireTimes = 1d , path=/
this.$cookies.config(expireTimes[,path])
//设置过期时间3天
this.$cookies.config('3d')
//浏览器会话结束时过期
this.$cookies.set("layout",this.layout,"0");
//永不过期
this.$cookies.set("layout",this.layout,-1);
-设置一个cookie
this.$cookies.set(keyName, value[, expireTimes[, path[, domain[, secure]]]])
-获取一个cookie
this.$cookies.get(keyName) // return value
-删除一个cookie
this.$cookies.remove(keyName [, path [, domain]]) // return this
-检查某个 cookie name是否存在
this.$cookies.isKey(keyName) // return false or true
-获取所有 cookie name,以数组形式返回
this.$cookies.keys() // return a array
|