首页 > 编程知识 正文

微信小程序封装wx.request,微信小程序封装工具类

时间:2023-05-03 17:53:54 阅读:270483 作者:790

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: '已经到底啦~~' }) }, })

版权声明:该文观点仅代表作者本人。处理文章:请发送邮件至 三1五14八八95#扣扣.com 举报,一经查实,本站将立刻删除。