微信小程序中页面间数据传递

一、在index.js页面

1、index.js中的goodspagedata方法从后台get的数据通过setData将数据shareData从逻辑层发送到视图层(我理解为将数据发送到Page({})下层和goodspagedata方法的同级)

2、然后在index.js的sharePoster方法中通过this.data.shareData拿到数据,再通过navigateTo将所需数据传送到post.js中

(从index页面跳转到post页面,并且把index页面的数据传递到post页面使用)

二、在post.js页面

1、在post.js页面中的onLoad事件的e参数中就包括index.js传递过来的数据,将数据通过setData从逻辑层发送到post.wxml视图层

post.js

post.wxml

猜你喜欢

转载自blog.csdn.net/weixin_43368919/article/details/83345575