参考博文地址:https://www.jb51.net/article/251545.htm
安装: cnpm install jsencrypt --save
使用(局部引用):
login.vue:
import JSEncrypt from 'jsencrypt'
const entry = new JSEncrypt()
const pubKey = 'xxxxx' //可以直接找后端要,也可以请求接口获取
entry.setPublicKey(pubKey)
login({
uuserPhone: this.loginForm.userPhone,
passWord: entry.encrypt(this.loginForm.password) //加密密码
}).then(res => {
if (result) {
console.log("登录成功") // 登录成功后的操作
} else {
// 登录失败操作
}
})