安装
1
2
3
>: cd 项目目录
>: cnpm install vue-cookie --save

配置:main.js
1
2
3
import cookie from 'vue-cookie'
Vue.prototype.$cookie = cookie;

使用:在任何方法中
1
2
3
4
5
6
7
8
9
10
11
12
13
14
// token是后台返回的

// 设置cookie
// this.$cookie.set(key, value, time)
this.$cookie.set('token', token, 1);

// 取出cookie
// this.$cookie.get(key)
console.log(this.$cookie.get('token'));

// 删除cookie
// this.$cookie.delete(key)
this.$cookie.delete('token');