Detailed explanation of WeChat applet navigateTo data transfer

小云云
Release: 2018-02-01 09:48:16
Original
3917 people have browsed it

This article mainly introduces relevant information to you about the examples of WeChat applet using navigateTo data transmission. I hope this article can help you. Friends in need can refer to it. I hope it can help you.

Instance of WeChat applet using navigateTo data transfer

1, passing basic data type

index. js Send page JS

Page({ 
 data: { 
  testStr: '字符串str' 
 }, 
 onLoad: function () { 
 }, 
 next: function(e){ 
  wx.navigateTo({ 
   url: '/pages/test/test?str='+this.data.testStr, 
  }) 
 } 
})
Copy after login

test.js Accept page JS

Page({ 
 data:{ 
 }, 
 onLoad:function(options){ 
  console.log("接收到的参数是str="+options.str); 
 } 
})
Copy after login

printed Log is as follows:

The received parameter is str=string str

2, passing object {}

index.js Send Page JS

Page({ 
 data: { 
  dataObj:{name:'我是name', extra:'我是extra'} 
 }, 
 onLoad: function () { 
 }, 
 toTest: function(e){ 
  wx.navigateTo({ 
   url: '/pages/test/test?dataObj='+JSON.stringify(this.data.dataObj) 
  }) 
 } 
})
Copy after login

test.js Accept page JS

Page({ 
 data:{ 
  dataObj:null 
 }, 
 onLoad:function(options){   
  this.dat.dataObj= JSON.parse(options.dataObj);//解析得到对象 
 }})
Copy after login

The printed Log is as follows :

test.js [sm]:16 The received parameter is obj={"name":"I am name","dataObj":"I am dataObj"}

3, pass the array collection []

index.js Send page JS

Page({ 
 data: { 
  list:['item-A','item-B'] 
 }, 
 onLoad: function () { 
 }, 
 next: function(e){ 
  wx.navigateTo({ 
   url: '/pages/test/test?list='+JSON.stringify(this.data.list), 
  }) 
 } 
})
Copy after login

test.js Accept page JS

Page({ 
 data:{ 
  list:[] 
 },  
onLoad:function(options){   
  console.log("接收到的参数是list="+options.list);//此处打印出来的是字符串,解析如下    
  this.data.list = JSON.parse(options.list);//解析得到集合
 }})
Copy after login

The printed Log is as follows:

test.js [sm]:17 The received parameter is list=["item-A" ,"item-B"]

Related recommendations:

Detailed explanation of Vue components and data transfer

How to implement Javascript Transfer data between forms?

How to transfer data between vue.js components

The above is the detailed content of Detailed explanation of WeChat applet navigateTo data transfer. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!