utils/asyncWX.js
export const showModal = ((content) => { return new Promise((resolve, reject) => { wx.showModal({ title: '提示', content, showCancel: true, cancelText: '取消', cancelColor: '#000000', confirmText: '确定', confirmColor: '#3CC51F', success: (result) => { resolve(result) }, fail: (err) => { reject(err) }, }); }) }) // await showToast('ddd666','success',400) 这个方法必须按照顺序书写 // export const showToast = ((title, icon = 'none', duration = 1500) => { // return new Promise((resolve, reject) => { // wx.showToast({ // title, // icon, // duration, // mask: true, // });// })// })// await show({ title: 'ddd' })这个写法的好处是传参不一定按照顺序写export const showToast = ({ title, icon = 'none', duration = 400 }) => { return new Promise((resolve, reject) => { wx.showToast({ title, icon, duration, mask: true, }); })}使用:
import { showModal } from "../../utils/asyncWX";Page({ async handelTrush() { let result = await showModal('确定要清空历史记录吗?') if (result.confirm) { wx.removeStorageSync('historyList'); this.setData({ historyList: [] }) } },})import { showToast } from "../../utils/asyncWX";Page({ async handelBottom() { await showToast({ title: '已经到底啦~~' }) }, })