你难道不知道Vue-cookie?

2022-06-03 17:55:09 浏览数 (2)

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.c o o k i e s . s e t ( ′ u s e r ′ , u s e r ) ; / / p r i n t u s e r n a m e c o n s o l e . l o g ( t h i s . cookies.set('user',user); // print user name console.log(this.cookies.set(′user′,user);//printusernameconsole.log(this.cookies.get(‘user’).name)

更多内容请见原文,原文转载自:https://blog.csdn.net/weixin_44519496/article/details/119353494

0 人点赞