vue中token存入cookie

一、vue之vue-cookies

npm链接:https://www.npmjs.com/package/vue-cookies

安装:

npm install vue-cookies --save

使用:

import Vue from 'Vue' import VueCookies from 'vue-cookies' Vue.use(VueCookies)

Api:

  设置 cookie:

this.$cookies.set(keyName, time) //return this

  获取cookie

this.$cookies.get(keyName) // return value

  删除 cookie

this.$cookies.remove(keyName) // return false or true , warning: next version return this; use isKey(keyname) return true/false,please

  查看一个cookie是否存在(通过keyName)

this.$cookies.isKey(keyName) // return false or true

  获取所有cookie名称

this.$cookies.keys() // return a array

参考文章:https://www.cnblogs.com/s313139232/p/9341762.html

二、 使用js-cookie工具

1.npm i js-cookie //安装

2.import Cookies from 'js-cookie' //引用

// 存入cookie:

Cookies.set('token','value')

// 获取cookie:

Cookies.get('token')

//删除cookie:

Cookies.remove('token')

你可能感兴趣的:(vue中token存入cookie)