vue项目中使用cookie
安装vue-cookies包:
npm install vue-cookies --save
在main.js中引入:
使用require:
var Vue = require('vue')
Vue.use(require('vue-cookies'))
若支持es6,则:
import Vue from 'Vue'
import VueCookies from 'vue-cookies'
Vue.use(VueCookies)
使用方法:
- set a cookie
this.$cookies.set(keyName, value[, expireTimes[, path[, domain[, secure]]]]) //return this
- get a cookie
this.$cookies.get(keyName) // return value
- remove a cookie
this.$cookies.remove(keyName [, path [, domain]]) // return false or true , warning: next version return this; use isKey(keyname) return true/false,please
- exist a cookie name
this.$cookies.isKey(keyName) // return false or true
- get all cookie name
this.$cookies.keys() // return a array
更多详细用法请看官网:vue-cookies