VUE 之 webpack 封装方法例子
encrypt.js
import { Base64 } from 'js-base64' // 加盐 let salting = 'shaozhu666' // 加密 const encryptString = (name) => { return Base64.encode(name + salting) } // 解密 const decodeString = (name) => { let decodeName = Base64.decode(name) || '' if (decodeName && decodeName.split && decodeName.split(salting) && decodeName.split(salting)[0]) { return decodeName.split(salting)[0] } else { return '' } } export { encryptString, decodeString }
在main js里面引入 并放在原型
import { encryptString, decodeString } from '@/utils/encrypt';//base 64 加密解密 Vue.prototype.encryptString = encryptString;//加密~ Vue.prototype.decodeString = decodeString;//解密~ // 在 .vue 文件内使用 this.encryptString this.decodeString