Home > Web Front-end > JS Tutorial > body text

WeChat mini program's unique method of passing parameters between pages

hzc
Release: 2020-07-02 09:37:17
forward
2726 people have browsed it

The mini program has its own dedicated routing method. After the basic library 2.7.3, the mini program specifically implements its own unique page parameter passing method, the success attribute in wx.navigateTo(). Of course, this method now only supports Use of wx.navigateTo()
Related document links: https://developers.weixin.qq.com/miniprogram/dev/api/route/wx.navigateTo.html

Usage examples are as follows

Page A

wx.navigateTo({
  url: 'pages/pageB',
  success: function(res) {
    // 通过eventChannel向被打开页面传送数据
    res.eventChannel.emit('goPageB', { pageDataA: '页面A传递到页面B的数据' })
  }
})
Copy after login

Page B

onLoad: function(){
    const eventChannel = this.getOpenerEventChannel()
    // 监听goPageB事件,获取上一页面通过eventChannel传送到当前页面的数据
    eventChannel.on('goPageB', function(data) {
      console.log('页面A传递的数据:',data)
    })
  }
Copy after login

This small program’s unique parameter passing method is slightly more troublesome than splicing url parameters. Some, but there is no need to perform relevant conversion of parameters, nor to process some special strings

Recommended tutorial: "WeChat Mini Program"

The above is the detailed content of WeChat mini program's unique method of passing parameters between pages. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:jianshu.com
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