【vue-cli】MD5插件

实际开发中前端有时会用到接口调用,签名安全等问题,因此会经常使用MD5进行签名,js-md5就是一款MD5加密插件,下面具体介绍用法:

1. 使用流程

(1)安装
vue-cli项目中安装

"js-md5": "^0.7.3",
 npm install  js-md5@0.7.3  --save

(2)作为Vue实例的方式使用
在main.js入口文件中

//引入
import md5 from 'js-md5'
// 挂载全局
Vue.prototype.$md5 = md5          // MD5

在组件中使用

//请求URL参数签名
this.$router.push({
    path: '/scm2erp/jxInputInvoice',
    query: {
      supplierNo: this.outParam.supplierNo,
      sign: this.$md5('jxInputInvoice' + this.outParam.supplierNo + 'SCM2ERP'),
      goods: this.goods,
      outParam: this.outParam
    }
})
//验证签名
mounted() {
  this.url = window.location.ancestorOrigins[0] + '/erp2/cw/service/ERPII'
  if (getUrlKey('sign') !== this.$md5('jxInputInvoice' + getUrlKey('supplierNo') + 'SCM2ERP')) {
    this.$router.push({ name: '404' })
  } else {
    this.goodsForm.goods = this.$route.query.goods
    this.outParam = this.$route.query.outParam
    console.log(this.$route.query.goods)
  }
}

2. 详细方法介绍

©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容