微信小程序界面跳转传值、反向传值
xxxixxxx

page1 点击事件 .wxml

1
<text bind:tap="pushNav">界面跳转传值</text>

page1 跳转方法实现 .js

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
pushNav(e) {

let that = this;
wx.navigateTo({
// 跳转传值方式 1
url: '../page2?carName=' + '特斯拉',

events: {
// 反向传值 page2 回调给 page1 接收处
getuserInfoClick(e) {
console.log(e);
that.setData({ userName: e.userName })
}
},
success: function (res) {
// 跳转传值方式 2
// 这个其实有点类似于通知的意思 定义通知名称 和 参数
res.eventChannel.emit('diyfunName', { parKey: '我是通过 eventChannel 传递的另一个数据' })
}
});
},

page2 接收传值,并回传 .js

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
/**
* 生命周期函数--监听页面加载
*/
onLoad: function (options) {

// 通过方式1 传值接收
this.setData({ carName: options.carName });

const eventChannel = this.getOpenerEventChannel();

let that = this;
// 反向传值 page2 传给 page1
eventChannel.emit('getuserInfoClick', { userName: '朱小明' });

// // 通过方式2 传值接收
eventChannel.on('diyfunName', function (params) {
that.setData({ otherPar: params.parKey });
});
},
  • Post title:微信小程序界面跳转传值、反向传值
  • Post author:xxxixxxx
  • Create time:2021-01-14 13:40:00
  • Post link:https://xxxixxx.github.io/2021/01/14/600-微信小程序-界面跳转传值/
  • Copyright Notice:All articles in this blog are licensed under BY-NC-SA unless stating additionally.
 Comments