front-end encryption

    // base64
    // md5 (md5是不可逆的)

base64

  1. Install dependencies
npm install --save js-base64
  1. Write in the page that needs to be used, if many pages need to be used, it can be directly introduced in main.js
let Base64 = require('js-base64').Base64
  1. use
Base64.encode(this.pwd);//加密
Base64.decode(this.pwd);//解密

md5 (md5 is irreversible)

  1. Install js-md5
npm install --save js-md5 
  1. Create a new folder called plugins under the src/ folder of the vue project, and then create a new md5.js file under plugins/, and write the following code
import md5 from 'js-md5'
 
export default {
    
    
  install: function (Vue) {
    
    
    Object.defineProperty(Vue.prototype, '$md5', {
    
     value: md5 })
  }
}
  1. In the src/main.js file of the vue project, write the following code
import md5 from './plugins/md5'
 
Vue.use(md5)
  1. use in component
<template>
  <div class="inventoryRecord">
    <h1>{
    
    {
    
     msg }}</h1>
  </div>
</template>
 
<script>
export default {
    
    
  name: 'inventoryRecord',
  data () {
    
    
    return {
    
    
      msg: 'Welcome to Your Vue.js App商品库存编辑记录',
      passWord: '123456'
    }
  },
  mounted () {
    
    
    let data = this.$md5(this.passWord)
    console.log(data)// e10adc3949ba59abbe56e057f20f883e
  }
}
</script>
 
<!-- Add "scoped" attribute to limit CSS to this component only -->
<style scoped>
</style>

Guess you like

Origin blog.csdn.net/m0_53912016/article/details/123925662