编码和解码
前端
cookie.save("user", window.encodeURI(JSON.stringify(res.data))
const user = JSON.parse(window.decodeURI(cookie.load("user") || "{}"));
java
string = URLEncoder.encode(string , "UTF-8"); //编码
string = URLDecoder.decode(string, "UTF-8"); // 解码
react操作coockie
yarn add react-cookies -D
import cookie from 'react-cookies'
存
cookie.save('userId', "123"{
path: '/',
expires,
maxAge: 1000, // maxAge 单位秒
domain: 'https://play.bukinoshita.io',
secure: true
httpOnly: true
})
取
cookie.load('userId')
删
cookie.remove('userId')
https://www.npmjs.com/package/react-cookies