Details and scenes of Events parameters in WeChat applet wx.navigateto method

Individual understanding of the Events parameter in wx.navigateto method and scenario

WeChat applet in version 2.7.3 wx.navigateto added Events This property
WeChat official document It is very vague in the community of WeChat public platform. I saw it first, I saw it first, I used to use the scene, and I found it just a copy of Copy official document, and I didn’t have any eggs. Everyone is a misty water, so uses spare time to study only, only the individual’s understanding, if there is a better idea or improper place, I hope that everyone will prevent my personal idea to mislead everyone

Personally understand this new attribute used scenario is to execute another page in a page, taking the most familiar shopping as an example, suppose now everyone is in the shopping order list, and then want to jump from this page to Comment on the order of the order, after the comment is completed, the order is refreshed, the original processing method is the operation of the comment to the order page to perform refresh orders in the onshow method, the user experience will be a little bit, and there is an events to solve it. This problem

// Order page js, order.js // Method for jump to the comment page FNTOCOMMENT () {wx.navigateto ({URL: ` ../ Comment / Comment`, Events: {// Perform a refresh order DATA is the parameter fnFefresh: function (data) {console.log (data) // receives Comment.js here from the comment page. {DATA: ‘2222’}}}}, success: function (res) {// Jump Comment page To execute method res. EventChannel.emit (‘fresh’, {data: ‘1111’})}})}, // comments page js, comment.jsvar eventChannelPage ({/ ** * page initial data * / data: {}, / ** * Life Cycle function – listen for page loads * / onLoad: function ( options) {eventChannel = this.getOpenerEventChannel () // event listener fresh, the data acquired is transferred to the previous page of the current page by eventChannel eventChannel.on ( ‘fresh’, function (data) {console.log (data) // this is received at the transmission order.js {data: ‘1111’}})}, submit comments method // refresh and refresh method fnComment order.js order of () {// refresh order.js properties of events fnFefresh method eventChannel.emit ( ‘fnFefresh’, {data: ‘2222’});}})
####### official documents delivered to this data is {data: ‘test’}, so that we may be kept, and in fact this transfer data between components vue somewhat similar, which is equivalent to emit for sending event, on receiving the same name, which is equivalent to emit transfer method, the page that is currently located (ie, page wx.navigateTo execution method) method emit in the open that is going to receive pages on the transfer of data, if the page is opened, there are executed the method of the current page while also calling method, it was opened on the page where there are local executive emit, the method in the current page in the events parameters in the receiving method is to be opened with the same name of the page will be able to emit received to execute a page is opened a method performed simultaneously emitThe data passed to the current page, that is, after the open page has been opened, performing a method can simultaneously call the way to execute the wx.navigateto method, personal understanding, using the scene, can perform another one on one page The page method, such as executing some refresh operations, preventing calling in onshow or being invited to the refresh process affecting the experience, personal understanding, do not like to spray

The above is all this article Content, I hope to help everyone, and I hope everyone will support Tumi Clouds.

© Copyright Notice
Just support it if you like
comment Grab the couch

Please log in to comment