首先用npm命令下载jsencrypt:
npm install jsencrypt --dep
在vue文件中引入jsencrypt
import { JSEncrypt } from 'jsencrypt'
对password加密:
this.encryptedData(this.form.password);
在methods中定义方法encryptedData:
// 加密
encryptedData(data) {
//私钥 和后端沟通写死了
var publicKey="";(很长的一串字符)
// 新建JSEncrypt对象
let encryptor = new JSEncrypt();
// 设置公钥
encryptor.setPublicKey(publicKey);
// 加密数据
return encryptor.encrypt(data);
},