路由传参页面刷新会丢失数据
有时候我们需要传递给另一个页面传递一个对象,或者是数组包着对象.但是会导致传递过去的数据在页面刷新后会丢失,针对这个问题可以用下面的解决方法:
也只能用query方式传参,通过JSON.stringify()将一个JavaScript值(对象或者数组)转换为一个 JSON字符串
//传参的页面
detail(row) {
let id = row.id ? row.id : '';
let userid = row.userid ? row.userid : '';
let Row=JSON.stringify(row);
this.$router.push({
name: 'examineResultDetail',
query: {
rwId: id,
userid: userid,
Row:Row
}
})
},
//接收参数的页面
data(){
form:{},
formRow:{},
}
this.formRow=JSON.parse(this.$route.query.Row);
this.form=this.formRow;