uni-app使用uni.navigateTo傳遞對象參數(shù)示例代碼
更新時間:2023年11月16日 15:32:43 作者:Bonsoir777
最近在做微信小程序用的是uniapp開發(fā)的,自己記錄一下,也和大家分享一下,這篇文章主要給大家介紹了關于uni-app使用uni.navigateTo傳遞對象參數(shù)的相關資料,需要的朋友可以參考下
一、傳遞一般參數(shù)
const index = 1; uni.navigateTo({ url: `../address/address?key=${index}` })
二、傳遞對象參數(shù)
1.傳遞參數(shù)
// 跳轉到訂單詳情頁面 toOrder(item) { // console.log(item.hpv_id, 'hpv_id') uni.navigateTo({ url: '../hpvOrder-detail/hpvOrder-detail?key=' + encodeURIComponent(JSON.stringify(item)) }) }
2.接收參數(shù)
navigateTo進行頁面?zhèn)鬟f參數(shù),在下一個頁面接收數(shù)據(jù),一般在在onLoad鉤子函數(shù)中獲取
onLoad(e) { this.detail = JSON.parse(decodeURIComponent(e.key)); console.log(this.detail) }
附:多個對象的傳遞
index頁面?zhèn)鬟f:
uni.navigateTo({ url: '/pages/setSeal/index?seal=' + encodeURIComponent(JSON.stringify(seal)) + '&cStorageModel' + encodeURIComponent(JSON.stringify(cStorageModel)) });
home頁面接收:
onLoad(option){ this.pageModel.sealAuth = JSON.parse(decodeURIComponent(option.sealAuth)); this.pageModel.cStorageModel = JSON.parse(decodeURIComponent(option.cStorageModel)); },
總結
到此這篇關于uni-app使用uni.navigateTo傳遞對象參數(shù)的文章就介紹到這了,更多相關uni.navigateTo傳遞對象參數(shù)內容請搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關文章希望大家以后多多支持腳本之家!