你难道不知道Vue-cookie?
installnpm install vue-cookies --savemain.jsimport VueCookies from 'vue-cookies'Vue.use(VueCookies)API:设置this.$cookies.set(keyName, time)获取this.$cookies.get(keyName)删除this.$cookies....
·
install
npm install vue-cookies --save
main.js
import VueCookies from 'vue-cookies'
Vue.use(VueCookies)
API:
设置
this.$cookies.set(keyName, time)
获取
this.$cookies.get(keyName)
删除
this.$cookies.remove(keyName)
查看一个cookie是否存在
this.$cookies.isKey(keyName)
获取所有cookie名称
this.$cookies.keys()
示例
json对象
var user = { id:1, name:'Journal',session:'25j_7Sl6xDq2Kc3ym0fmrSSk2xV2XkUkX' };
this.$cookies.set('user',user);
// print user name
console.log(this.$cookies.get('user').name)
过期时间
默认为1天
简写 | 全名 |
---|---|
y | year |
m | month |
d | day |
h | hour |
min | minute |
s | second |
this.$cookies.set("default_unit_second","input_value",1); // 1秒之后
this.$cookies.set("token","GH1.1.1689020474.1484362313","60s"); // 60秒之后,
this.$cookies.set("token","GH1.1.1689020474.1484362313","30MIN");//30分钟之后 ,不区分大小写
this.$cookies.set('token',"GH1.1.1689020474.1484362313", new Date(2017,3,13).toUTCString());//某一天
this.$cookies.set("token","GH1.1.1689020474.1484362313", "Sat, 13 Mar 2017 12:25:57 GMT ");//某一时刻
this.$cookies.set("token","GH1.1.1689020474.1484362313", Infinity); // 永不过期
this.$cookies.set("token","GH1.1.1689020474.1484362313", -1); //永不过期
更多推荐
已为社区贡献49条内容
所有评论(0)