安装: npm install vue-cookies --save
引用
main.js中设置
// vue-cookies配置 import cookies from 'vue-cookies' Vue.prototype.$cookies = cookies;
1、设置cookie
this.$cookies.set(keyName, value[, expireTimes[, path[, domain[, secure]]]]) //return this // 简洁使用 this.$cookies.set('key','value', '过期时间,按秒计'); // 示例 this.$cookies.set('username',response.data.username, '张三');
2、获取cookie
this.$cookies.get(keyName) // return value
3、删除cookie
this.$cookies.remove(keyName);
4、判断cookie中是否有指定的key
this.$cookies.isKey(keyName)
5、获取所有cookie
this.$cookies.keys()