1. 程式人生 > 其它 >vue使用query傳參,重新整理頁面資料丟失

vue使用query傳參,重新整理頁面資料丟失

技術標籤:vue

使用params路由傳參的時候資料會丟失,所以選擇了query,但是重新整理頁面的時候報錯 [object,object]
記錄:

component:  demo1
let data={id:1;name:"張三"}
 this.$router.push({path:'/demo2',query:{data:data}}) 
component2:  demo2
let tableData=this.$route.query.data

重新整理頁面列印 tableData報錯
在這裡插入圖片描述
解決辦法如下:

component:  demo1
 this.$router.push({path:'/demo2',query:{data:JSON.stringify(data)}}) 
component2:  demo2
let tableData=this.$route.query.data
this.tableList=JSON.parse(tableData)