1、安装依赖
npm install jsencrypt --save
安装完了后package.json中会有 "jsencrypt": "^3.2.1"
2、在main.js中引入 jsencrypt
import { JSEncrypt } from 'jsencrypt'
3、挂载全局方法
Vue.prototype.$getCode = (password)=> {
const encrypt = new JSEncrypt()
// 公钥
const publicKey = '此处填写公钥'
encrypt.setPublicKey(publicKey) // 此处设置公钥
const data = encrypt.encrypt(password) // 这里对密码进行加密
return data
}
4、使用方法
const data = this.$getCode(this.password) //这样传给接口就行