Three ways to jump to the WeChat applet page (with Chinese parameters)

1.wx.navigateTo Sample code for passing parameters (no Chinese):

// 在当前页面进行跳转,同时传递参数 param1 和 param2
wx.navigateTo({
  url: '/pages/myPage/myPage?param1=value1&param2=value2'
})

 1.wx.navigateTo Sample code for parameter passing (with Chinese):

 pass:

wx.navigateTo({
  url: '/pages/detail/detail?id=' + encodeURIComponent("带中文的参数")       
})

 catch:

 onLoad: function (options) {
    console.log(decodeURIComponent(options.id)) // 输出 "带中文的参数"
 }

 2. wx.redirectTo Sample code for parameter passing:

// 关闭当前页面,直接打开 pages/index/index 页面,并传递参数 id=1
wx.redirectTo({
  url: '/pages/index/index?id=1'
})

 3. wx.reLaunch Sample code for parameter passing:

// 关闭所有页面,直接打开 pages/login/login 页面,并传递参数 username='John' 和 password='123'
wx.reLaunch({
  url: '/pages/login/login?username=John&password=123'
})

In these sample codes, the url parameter specifies the path of the page that needs to be opened, and at the same time pass the parameter that needs to be passed through the ? after the path. In the page being navigated to, the passed parameters can be obtained through onLoadthe method . For example, in myPagethe page, you can get the passed parameter value like this:

onLoad: function(options) {
  console.log(options.param1) // 输出 value1
  console.log(options.param2) // 输出 value2
}

 

Guess you like

Origin blog.csdn.net/m0_64590669/article/details/130172612