Closed youngjuning closed 5 years ago
getCurrentPages()
获取栈中全部页面的, 然后把数据写入相应页面const curPages = getCurrentPages()
wx.navigateBack({
delta: 1, // 回退前 delta(默认为1) 页面
success: () => {
curPages[curPages - 2].setData({
address: {
name: '',
phone: '',
province: '',
city: '',
district: '',
town: '',
addressId: ''
})
}
})
注:这个方法适合 往后面传值(即已经存在的页面), 这样才能在栈中找到并主动写入数据
<view bindtap="onTap" id="{{item.id}}">
...
</view>
在 bindtap
定义的点击方法 swiperTap : function(e)
中获取:
const id = e.currentTarget.id
data-xxx
的方法来标识要传递的值<view bindtap="onTap" id="{{item.id}}" data-page_title="{{item.page_title}}" data-banner_id="{{item.banner_id}}">
...
</view>
在bindtap定义的点击方法 swiperTap : function(e) 中获取, 即:
let page_title = e.currentTarget.dataset.page_title
let banner_id = e.currentTarget.dataset.banner_id
wxml:
<form bindsubmit="onSubmit">
<input name="detail" placeholder="详细地址"/>
<input name="name" placeholder="收件人姓名">
<input name="phone" placeholder="手机号码" type="number">
<input bindconfirm="onConfirm">
</form>
js:
onSubmit: (e) => {
const { detail, name, phone } = e.detail.value
}
onConfirm: (e) => {
const value = e.detail.value
}
页面传值
1、用 navigator 标签或 路由API传值:
这里将
good_id=16
参数传入 detail 页面, 然后 detail 页面的onload
方法内接收:如果需要传多个参数,用
&
链接即可:接收方法:
如果要传 数组, 字典等复杂类型, 要先用
JSON.stringify()
转成字符串传递.2、用
getCurrentPages()
获取栈中全部页面的, 然后把数据写入相应页面先获取全部页面, 取出来是个数组, 然后用下标定位
3、用
wx.setStorage
写入本地, 再用wx.getStorage
读取出来4、把 数据声明为全局变量, 可在任何页面获取