傳字符串
#傳送
this.$router.push({
name: `TestVueRouterTo`,
params: {
page: '1', code: '8989'
}
})
#接收
getRouterData() {
this.page = this.$route.params.page
this.code = this.$route.params.code
console.log('page', this.page)
console.log('code', this.code)
}
參考網(wǎng)頁:https://www.cnblogs.com/beka/p/8583924.html
傳對(duì)象
在路由傳參中勺馆,只能傳取字符串春塌,如果需要傳對(duì)象的話刺啦,需將字符串靠JSON轉(zhuǎn)為字符串末患。接收后靠JSON解析
傳:
// 列表頁點(diǎn)擊跳轉(zhuǎn)
let data = JSON.stringify(result) // result傳遞的query參數(shù)军洼。我們轉(zhuǎn)為string
this.$router.push({path: '/wx/detail', query: {res: data}})
收:
// 詳情頁獲取
let data = JSON.parse(this.$route.query.res)
this.result = Object.assign({}, data)
參考網(wǎng)頁:https://www.cnblogs.com/mmzuo-798/p/10286970.html