仅支持浏览器端:

// 字符串编码
function encode (str) {
    return window.btoa(encodeURIComponent(str))
}

// 字符串解码
function decode(str) {
    return decodeURIComponent(atob(str))
}

console.log(encode('yangyingjie'))

小生不才
3 声望0 粉丝