在这里插入代码片
vue项目中使用rsa加密
1.安装依赖
npm install jsencrypt --save
2.在main.js引入
import { JSEncrypt } from 'jsencrypt'
3.挂载全局方法
Vue.prototype.$getCode = (password)=> {
let encrypt = new JSEncrypt()
encrypt.setPublicKey(‘公钥‘)
let data =encrypt.encrypt(password);
return data
}
4.使用方法
let data = this.$getCode(this.password) 这样传给接口就行