uniapp develops WeChat applet - jump to the page and pass complex data types

在跳转前,将需要传递的对象参数转为JSON字符串,然后用encodeURIComponent进行编码,拼接在url后面。

  • In uni-app, to implement page jump and pass object parameters, you can use the following methods:
     var navData = JSON.stringify(id); // 也可以不要JSON.stringify(),这里只是把他转化为字符串的形式,如果本来就是字符串,那么就不需要这一步
    				uni.navigateTo({
    					url:'../gridManagement/gridManagement?id=' + navData
    
    

2. Page reception and use

在跳转后的页面,通过onLoad事件获取传递的对象参数,并使用decodeURIComponent解码,然后转为对象。
 

onLoad(options) {
			var data = options.id; //如果传递参数过来的页面有将其转化为字符串,那么这边就有一个JSON.parse()字符串转对象的步骤
			this.navData = data
			console.log(this.navData)
	}

3. Supplementary method (simple and crude)

  • JSON.stringify()Use convert to string on current page
  • JSON.parse()Use parsing on the page after the jump

Guess you like

Origin blog.csdn.net/weixin_62635213/article/details/132817718