小程序选择门店后带参返回上一页
子页(需要选择的):
wxml:
<view class="box2" wx:for="{{store}}">
<view class="box2_son1" data-id="{{index}}" bindtap="backIndex">
<view class="box2_son1_left">{{item.store_name}}</view>
<view class="box2_son1_right" wx:if="{{item.num == 1 }}">距您最近的门店</view>
<view class="box2_son1_right" wx:else></view>
</view>
</view>
js:
// 选择门店回上一页(首页)
backIndex: function (e) {
console.log('回首页!!!!')
var me = this;
let idindex = e.currentTarget.dataset.id;
var stores = me.data.data.data;
var dis = stores[idindex].dis
var id = stores[idindex].id
console.log(stores)
console.log(idindex)
console.log(dis)
console.log(id)
App._post_form('Storeinfo/sele', {id: id,km: dis}, result => {
var touch_data = result.data.data;
var touch_id = touch_data.id;
var touch_store_name = touch_data.store_name;
me.setData({
touch_data: touch_data,
touch_id: touch_id,
touch_store_name: touch_store_name,
})
var pages = getCurrentPages();
var prevPage = pages[pages.length - 2]; //上一个页面
//直接调用上一个页面的setData()方法,把数据存到上一个页面中去
prevPage.setData({
mydata: {
touch_id: touch_id,
touch_store_name: touch_store_name,
}
})
wx.navigateBack({//返回
delta: 1
})
}, false, () => {
wx.hideLoading();
});
},
父页(需要选择后显示的):
wxml:
<view class="here_name" wx:if="{{touch_store_name}}">{{touch_store_name}} ></view>
<view class="here_name" wx:else>{{jingwei}} ></view>
js:
data: {
mydata: [],
touch_store_name: "",
}
在onShow里面写:
// 接收门店页面传过来的值
var pages = getCurrentPages();
var currPage = pages[pages.length - 1]; //当前页面
let json = currPage.data.mydata;
let touch_store_name = json.touch_store_name;
console.log(json)//为传过来的值
console.log(touch_store_name)//为传过来的门店名
_this.setData({
touch_store_name: touch_store_name
})



参考链接:https://www.cnblogs.com/ldlx-mars/p/10598708.html

浙公网安备 33010602011771号