前端先看有无.eslintrc.js文件,添加 rules 和 'globals'
TypeScript
rules: {
'no-console': process.env.NODE_ENV === 'production' ? 'warn' : 'off',
'no-debugger': process.env.NODE_ENV === 'production' ? 'warn' : 'off',
},
"globals":{
"base64js": true,
}
安装SM4
TypeScript
npm install sm4util
新建utils文件,引入使用
TypeScript
//引入和使用
import {SM4Util} from "sm4util";
const sm4 = new SM4Util();
TypeScript
<template>
<div>
<input v-model="mobilePhone" placeholder="请输入手机号">
<input v-model="password" placeholder="请输入密码">
</div>
</template>
<script>
import {SM4Util} from '@/utils/sm4';
export default {
name: "Register",
data(){
return{
username: '',
mobilePhone: '',
password: '',
rePassword: ''
}
},
mounted() {
const sm4 = new SM4Util();
const test = sm4.encryptData_CBC('123456')
console.log('123456的加密结果:' + test)
},
methods:{
register(){
// sm4加密
const sm4 = new SM4Util();
this.$axios
.post("/user/register", {
mobilePhone: this.mobilePhone.trim(),
password: sm4.encryptData_CBC(this.password.trim()),
})
}
}
}
</script>
后端也需要安装相应的SM4,以此来解析