一、MD5加密
1. 使用npm 安装:npm install --save js-md5
2. 在main.js中:import md5 from 'js-md5';
Vue.prototype.$md5 = md5;
3.methods中定义方法,然后调用
setMd5(){
this.$md5('hello world') // 5eb63bbbe01eeed093cb22bb8f5acdc3
},
二、Base64加密
1.npm 安装 npm install js-base64
2.跟上面一样,不啰嗦。
setBase(){
let Base64 = require("js-base64").Base64
this.pw = Base64.encode(this.passWord)
console.log(this.pw)
}
三、sha256
1.使用npm安装 :npm install js-sha256
2.然后在组件中methods定义方法,在调用
setSha(){
let sha256 = require("js-sha256").sha256//这里用的是require方法,所以没用import
this.pw = sha256(this.passWord)//要加密的密码
console.log(this.pw)//这就是你加密之后的密码
},