安裝:javascript
npm install vue-cookies
使用:html
import Vue from 'Vue' import VueCookies from 'vue-cookies' Vue.use(VueCookies)
// 有響應的登陸認證碼,存儲在cookie中 // 設置:set(key, val, exp) // 取值:get(key) // 刪除:remove(key) let token = response.data.result; if (token) { // this.$cookies.set('token', token, '2d'); // this.$cookies.set('token', token, 2 * 24 * 3600 * 365); // console.log(this.$cookies.get('token')); // this.$cookies.remove('token'); }
Api:前端
設置 cookie:vue
this.$cookies.set(key, val, exp) //return this
獲取cookiejava
this.$cookies.get(key) // return value
刪除 cookienpm
this.$cookies.remove(key) // return false or true , warning: next version return this; use isKey(keyname) return true/false,please
查看一個cookie是否存在(經過keyName
)cookie
this.$cookies.isKey(key) // return false or true
獲取全部cookie名稱this
this.$cookies.keys() // return a array
來源:https://www.cnblogs.com/liuqingzheng/articles/9850874.htmlcode