vue 的base64加密解密
1.新建一个文件
加入代码
const Base64 = { //加密 encode(str) { return btoa(encodeURIComponent(str).replace(/%([0-9A-F]{2})/g, function toSolidBytes(match, p1) { return String.fromCharCode('0x' + p1); })); }, //解密 decode(str) { return decodeURIComponent(atob(str).split('').map(function (c) { return '%' + ('00' + c.charCodeAt(0).toString(16)).slice(-2); }).join('')); } } export default Base64 2.在主体文件main.js中进行设置(引入和暴露出来) import Base64 from "./assets/js/base64.js" 路径写法:Vue.prototype.$Base64 = Base64; 暴露: 3.在需要加密的页面中进行加密: 加密的方式有两种: 3-1单个数据加密 this.$Base64.encode() 3-2.多数据加密(对象) this.$Base64.encode(JSON.stringify(params)) 4.在对应的文件中解密 解密也分两种: 4-1.单个数据解密 this.$Base64.decode() 4-2.多个数据解密(对象) JSON.parse(this.$Base64.decode(this.$route.query.id))