日本免费高清视频-国产福利视频导航-黄色在线播放国产-天天操天天操天天操天天操|www.shdianci.com

學(xué)無(wú)先后,達(dá)者為師

網(wǎng)站首頁(yè) 編程語(yǔ)言 正文

UNI-APP頁(yè)面跳轉(zhuǎn)時(shí)(uni.navigateTo),參數(shù)傳遞

作者:滄海龍騰LV 更新時(shí)間: 2024-02-29 編程語(yǔ)言

方法一:

1、在起始頁(yè)面跳轉(zhuǎn)到test.vue頁(yè)面并傳遞參數(shù)

//在起始頁(yè)面跳轉(zhuǎn)到test.vue頁(yè)面并傳遞參數(shù)
uni.navigateTo({
    url: 'test?id=1&name=uniapp'
});

2、在test.vue頁(yè)面接受參數(shù)

export default {
    onLoad: function (option) { //option為object類型,會(huì)序列化上個(gè)頁(yè)面?zhèn)鬟f的參數(shù)
        console.log(option.id); //打印出上個(gè)頁(yè)面?zhèn)鬟f的參數(shù)。
        console.log(option.name); //打印出上個(gè)頁(yè)面?zhèn)鬟f的參數(shù)。
    }
}

方法二(傳遞json對(duì)象):

url有長(zhǎng)度限制,太長(zhǎng)的字符串會(huì)傳遞失敗,可改用窗體通信、全局變量,另外參數(shù)中出現(xiàn)空格等特殊字符時(shí)需要對(duì)參數(shù)進(jìn)行編碼,如下為使用encodeURIComponent對(duì)參數(shù)進(jìn)行編碼的示例。

<navigator :url="'/pages/test/test?item='+ encodeURIComponent(JSON.stringify(item))"></navigator>
// 在test.vue頁(yè)面接受參數(shù)
onLoad: function (option) {
    const item = JSON.parse(decodeURIComponent(option.item));
}

完!!!

代碼示例:

/*跳轉(zhuǎn)到詳情頁(yè)*/
			gotoDetail(item){
				uni.navigateTo({
					//url: '/pages/index/device/detail/detail?code='+item.adapterCode+'&type='+item.type+'&id='+item.id
					url: '/pages/index/device/detail/detail?item='+encodeURIComponent(JSON.stringify(item))
				})
			},
onLoad(option) {
			const item = JSON.parse(decodeURIComponent(option.item));
			console.log(item)
		},

?

?

?

原文鏈接:https://ly9527.blog.csdn.net/article/details/115691922

  • 上一篇:沒(méi)有了
  • 下一篇:沒(méi)有了
欄目分類
最近更新