解决小程序开发中,不支持 atob 函数问题,can not find variable:atob,window.atob 未定义、无法使用
解决小程序开发中,不支持 atob 函数问题,can not find variable:atob,window.atob 未定义、无法使用。写一个 base64 解码函数替代使用即可,代码如下
省流,直接亮代码
复制
export function base64Decode(base64) {
const chars = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=';
let str = '';
let buffer = 0;
let bits = 0;
for (let i = 0; i < base64.length; i++) {
const c = base64.charAt(i);
const index = chars.indexOf(c);
if (index === -1) {
continue;
}
buffer = (buffer << 6) | index;
bits += 6;
if (bits >= 8) {
bits -= 8;
str += String.fromCharCode((buffer >> bits) & 0xFF);
}
}
return str;
}
作者:https://blog.xn--rpv331d.com/望舒
链接:https://blog.xn--rpv331d.com/望舒/blog/38
转载注意保留文章出处...
0
1
0
61
No data