フロントエンド暗号化

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

base64

  1. 依存関係をインストールする
npm install --save js-base64
  1. 使用する必要のあるページに書き込みます。多くのページを使用する必要がある場合は、main.jsに直接導入できます。
let Base64 = require('js-base64').Base64
  1. 使用する
Base64.encode(this.pwd);//加密
Base64.decode(this.pwd);//解密

md5(md5は元に戻せません)

  1. js-md5をインストールします
npm install --save js-md5 
  1. vueプロジェクトのsrc/フォルダーの下にpluginsという名前の新しいフォルダーを作成し、次にplugins /の下に新しいmd5.jsファイルを作成して、次のコードを記述します。
import md5 from 'js-md5'
 
export default {
    
    
  install: function (Vue) {
    
    
    Object.defineProperty(Vue.prototype, '$md5', {
    
     value: md5 })
  }
}
  1. vueプロジェクトのsrc/main.jsファイルに、次のコードを記述します
import md5 from './plugins/md5'
 
Vue.use(md5)
  1. コンポーネントでの使用
<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>

おすすめ

転載: blog.csdn.net/m0_53912016/article/details/123925662