原始代码:
// 当前页面路由
handleDetail(row, type) {
this.$router.push({
path: '/dependencies/detail',
query: {
detailData: row, // row为一个对象
type: type
}
})
}
// 跳转到此页面
created() {
this.type = this.$route.query.type
this.detailData =this.$route.query.detailData // 刷新后,this.detailData='[Object Object]'
}
解决方法:使用JSON.stringify()将要传的对象转为字符串,接收时使用JSON.parse()转为对象
现在代码:
handleDetail(row, type) {
this.$router.push({
path: '/dependencies/detail',
query: {
detailData: JSON.stringify(row),
type: type
}
})
}
created() {
this.type = this.$route.query.type
this.detailData =JSON.parse(this.$route.query.detailData)
}