npm install js-cookie
<script src="https://cdn.jsdelivr.net/npm/js-cookie@2/src/js.cookie.min.js"></script>
import Cookies from ‘js-cookie‘
// 设置名称和值;如果不设置过期日期,当前浏览器关闭前生效;
Cookies.set(‘name‘, ‘value‘)
// 7天后过期
Cookies.set(‘name‘, ‘value‘, { expires: 7 })
// 对当前路径有效的cookie
Cookies.set(‘name‘, ‘value‘, { expires: 7, path: ‘‘ })
// 读取指定名cookie
Cookies.get(‘name‘)
// 读取所以cookie
Cookies.get()
// 删除cookie
Cookies.remove(‘name‘, { path: ‘‘ })
Cookies.remove(‘name‘)
原文:https://www.cnblogs.com/kgwei520blog/p/15267339.html