在vue项目中使用md5加密的方法

这篇文章主要介绍了在vue项目中使用md5加密的方法,需要的朋友可以参考下

npm安装:

npm install --save js-md5

1.在需要使用的项目文件中引入:

import md5 from 'js-md5';

使用:

md5('hello world')  // 5eb63bbbe01eeed093cb22bb8f5acdc3

2.或者在main.js文件中将md5转换成vue原型:

 import md5 from 'js-md5'; Vue.prototype.$md5 = md5; 

使用:

 this.$md5('hello world') // 5eb63bbbe01eeed093cb22bb8f5acdc3 

vue使用md5加密的实例代码

 import crypto from 'crypto' export default { name: 'HelloWorld', data () { return { msg: 'Welcome to Your Vue.js App' } }, mounted(){ this.getmd5("aaa"); }, methods:{ getmd5(str){ var a; var md5 = crypto.createHash("md5"); //update("中文", "utf8") md5.update(str); var a = md5.digest('hex'); console.log(a); //47bce5c74f589f4867dbd57e9ca9f808 return a; } } }

总结

以上就是在vue项目中使用md5加密的方法的详细内容,更多请关注0133技术站其它相关文章!

赞(0) 打赏
未经允许不得转载:0133技术站首页 » Vue.js 教程