Vue-Router中Query传值简单加密

Published on
53
//由于url有长度限制,所以这个解决方案不能携带太多参数
router.push({
  name: "Consumption",
  query: encodeURIComponent(
    btoa(JSON.stringify({ id: data.id, name: data.name }))
  ),
});
//跳转到的页面
 const query = router.currentRoute.value.query; // 获取当前路由的 query 参数
 const decodedQuery = JSON.parse(
  decodeURIComponent(atob(query)) // 解码 query
);

console.log(decodedQuery); // { id: data.id, name: data.name }

如果需要更麻烦的加密的话,用crypto-js 实现更复杂的加密方法。

https://www.npmjs.com/package/crypto-js

加密只是增加了破解所需要的成本和时间


Prev Post Puppeteer避免被检测
Next Post NestJS中不同环境的切换