Page({
data: {
list: []
},
onLoad(options) {
}
tapItem(e) {
const index = e.currentTarget.dataset.index * 1
const item = this.data.list[index]
if (typeof this.success === 'function') {
this.success(item)
wx.navigateBack()
}
}
})
let addEvent
addEvent = function(oldPageCount, fn) {
const pages = getCurrentPages()
if (pages.length > oldPageCount) {
pages[pages.length - 1].success = fn
} else {
setTimeout(addEvent, 300)
}
}
module.exports = {
selectAddress: async () => {
let pageCount = getCurrentPages()
return new Promise((resolve, reject) => {
wx.navigateTo({
url: '/pages/address-select',
success() {
addEvent(pageCount, res => {
resolve(res)
})
}
})
})
}
}
其他页面或者组件中使用啦
import { selectAddress } from 'address-select'
const address = await selectAddress()