当前位置:网站首页>04 route jump and carry parameters

04 route jump and carry parameters

2022-06-13 02:27:00 JSONP$

04 The route jumps and carries parameters

First write a button Button , Bind an event to it

<button bindtap="skip" type="primary"> Jump </button>

Then bind a parameter for him

<button bindtap="skip" type="primary" data-name=" Zhu Yuan "> Jump </button>

Then write jump logic for this event

  skip(){
    
   wx.navigateTo({
    
      url: '/pages/logs/logs'
  })
   },

Be careful !!! In actual development, we will encounter , A particularly curious question , That is, your paths are all written to , The jump mode is also written against , But I still can't jump . This is because there is a cache , Or not updated in time , We can clearly cache , And re import this project , It's back to normal , This is also a part of wechat applet bug. Or you don't do anything , Wait for more than ten minutes , The jump function of this item can also return to normal .

Let's see how to implement the parameter carrying function , Because in html page , We have carried a parameter in the following way , We now need to pass this parameter to the page after jump

data-name=" Zhu Yuan "

Let's look at the following actual code

 Insert a code chip here 

Be sure to open the domain name that is not verified as legal , Otherwise, there is no way to get the carried parameters
 Insert picture description here
Be careful ! At this point, if there is bug, We need to close this project , Then re import the following , In this way, wechat applet developer tools are sometimes quite lame . We can achieve a re import effect by debugging the basic library
 Insert picture description here
then , We can get this parameter on another page

 onLoad: function (options) {
    
    console.log(options.name);
    
  },

Wechat applet has also prepared a special label for us to realize jump

<navigator open-type="navigate" url="pages/index/index"> Jump </navigator>

open-type This attribute can be left blank , The default is navigate

So how to pass on parameters ?

<navigator open-type="navigate" url="pages/index/index?id=1"> Jump </navigator>

Receive this parameter from another page , The same way

 onLoad: function (options) {
    
    console.log(options.name);
    
  },

Recently, many problems have been found in the code , The latest version of wechat developer tool has been solved

 That is, your paths are all written to , The jump mode is also written against , But I still can't jump 

This problem , No need to reload the project , It's not going to happen bug 了 , But the latest version of wechat developer tools can not be used perfectly vant Component library , This is very uncomfortable , Because it doesn't have

 Use npm modular 

This option

原网站

版权声明
本文为[JSONP$]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/164/202206130223453892.html