1、在项目根目录下安装
npm install --save js-base64
2、在项目文件中引入
let Base64 = require('js-base64').Base64
3、在项目文件中使用
Base64.encode() // 编码
Base64.decode() // 解码
this.res = res;
console.log(res); //eyJpZCI6IDEsICJuYW1lIjogImFkbWl...;
console.log(this.res.session); //undefined
this.res = Base64.decode(res);
console.log(this.res); //{"id": 1, "name": "admin", "session": "6acf5137-b75..."}
console.log(typeof this.res); //string
this.res = JSON.parse(this.res);
console.log(this.res);
/* {id: 1, name: "admin", session: "6acf5137-b75c-3e68..."}
id: 1
name: "admin"
session: "6acf5137-b75c-3e68-b085-bf76a2c55c41"
__proto__: Object
*/
console.log(this.res.session); //5ec879dd-20bc-33f4-aeed-9741f951bfd9