1.安装依赖
npm install --save js-base64
2.全局引入 main.js
import * as Base64 from 'js-base64'
Vue.prototype.Base64 = Base64
3.在页面中使用
加密
<router-link
:to="{
path: '/List',
query: { info: Base64.encode(JSON.stringify({ title: '这里是标题', module: 2 })) }
}"
>更多
</router-link>
getDetails(module, title, id) {
let param = {
module: module,
title: title,
articleId: id
}
this.$router.push({
path: '/details',
query: {
info: this.Base64.encode(JSON.stringify(param))
}
})
},
解密
created() {
let param = JSON.parse(this.Base64.decode(this.$route.query.info))
}