- 原始cookies数组
0: _sna=aaa; Path=/
1: JSESSIONID=bbb; Path=/abc-web; HttpOnly
2: uid=ccc;path=/;HTTPOnly; - 目的
每个元素后面都有path,有用的部分是path之前的_sna,JSESSIONID和uid。所以处理的目的就是把这些提出来,再用分号拼接成字符串:
"_sna=aaa; JSESSIONID=bbb; uid=ccc"
// 重组和拼接cookie,res是请求的返回内容
var cookieStr = "";
var cookieArr = new Array();
res.cookies.forEach((item, index, array) => {
// split 根据";"分割字符串
cookieArr.push(item.split(";")[0]);
});
// join 根据";"拼接字符串
cookieStr = cookieArr.join(";");
wx.setStorageSync("cookies", cookieStr);
网友评论