base64解密加密中⽂乱码解决let Base64 = {
encode(str) {
// first we use encodeURIComponent to get percent-encoded UTF-8,
// then we convert the percent encodings into raw bytes which
slice中文
// can be fed into btoa.
return btoa(encodeURIComponent(str).replace(/%([0-9A-F]{2})/g,
function toSolidBytes(match, p1) {
return String.fromCharCode('0x' + p1);
}));
},
decode(str) {
/
/ Going backwards: from bytestream, to percent-encoding, to original string.
return decodeURIComponent(atob(str).split('').map(function (c) {
return '%' + ('00' + c.charCodeAt(0).toString(16)).slice(-2);
}).join(''));
}
};
let encoded = de("哈ha"); // "5ZOIaGE="
let decoded = Base64.decode(encoded); // "哈ha"
  react 中使⽤
新建⽂件base.js
// base64解密加密中⽂乱码解决
let Base64 = {
encode(str) {
// first we use encodeURIComponent to get percent-encoded UTF-8,
// then we convert the percent encodings into raw bytes which
// can be fed into btoa.
return btoa(encodeURIComponent(str).replace(/%([0-9A-F]{2})/g,
function toSolidBytes(match, p1) {
return String.fromCharCode('0x' + p1);
}));
},
decode(str) {
/
/ Going backwards: from bytestream, to percent-encoding, to original string.
return decodeURIComponent(atob(str).split('').map(function (c) {
return '%' + ('00' + c.charCodeAt(0).toString(16)).slice(-2);
}).join(''));
}
};
export default Base64
  在组件中使⽤
//  ⼿动引⼊base64解密加密中⽂乱码解决
import Base64 from "../ways/basecode";
let encoded = de("哈ha"); // "5ZOIaGE="
let decoded = Base64.decode(encoded); // "哈ha"