为了防止地址栏出现类似于id之类的敏感信息,需要将地址栏传参改为缓存,地址栏隐藏传参数据
vue官网 页面跳转
const lookInfo = (row) => {
router.push({
name: "ServeInfo",
query: { id: 12345, nodeId: '', tab: '', formPage: 'AgencyTask' },
});
}
地址栏:https://,,,,/ServeInfo?id=12345&nodeId=&tab=&formPage=AgencyTask
解决方法 ----》 采用缓存
----------store/index.js-----------
import { defineStore } from "pinia";
export const useStore = defineStore("main", {
state: () => {
return {
routeParams: {},//页面传参(地址栏改缓存)
}
},
getters: {
double: (state) => { return state.purview + 1 }
},
actions: {
setRouteParams(params) {
this.routeParams = Object.assign(this.routeParams, params)
},
clearRouteParams(params) {
if (this.routeParams[params]) {
delete this.routeParams[params]
}
},
clearAllRouteParams() {
this.routeParams = {}
},
},
// 开启数据缓存
persist: {
enabled: true,
strategies: [
{
key: "routeParams",
storage: sessionStorage,
paths: ["routeParams"]
},
]
}
})
使用-----
const A =()=>{
router.push({id
name: "B页面",
// query: { type: "file", id:11111 },
});
store.setRouteParams({ manageInfo: { type: "file", id: 11111} });
}
B页面 接收使用参数----------
import { useStore } from "@/stores"
const store = useStore()
const idNew= store.routeParams.manageInfo.busiCode