首页 > 微信 > 详细

微信小程序wx.request,wx.showToast,wx.showLoading,wx.showModal的简易封装

时间:2020-05-18 19:05:51      阅读:106      评论:0      收藏:0      [点我收藏+]

/**
 * request 配置
 */
const request = (url, method = ‘GET‘, data = {}) => {
    const ULR = url.indexOf(‘http‘) !== -1 ? url : getApp().globalData.env.BASE_URL + url
    return new Promise((resolve, reject) => {
            wx.request({
            url: ULR,
            data: data,
            method: method,
            success(res) {
                resolve(res.data)
            },
            fail(res) {
                reject(res)
            }
        })
    })
}

/**
 * showToast
 */
const showToast = (title, icon = ‘none‘, speed = 2000) => {
    wx.showToast({
        title: title,
        icon: icon,
        duration: speed
    })
}

/**
 * showLoading
 */
const showLoading = title => {
    wx.showLoading({
        title: title,
        mask: true
    })
}

/**
 * showModal
 */
const showModal = (title, content, callback) => {
    wx.showModal({
        title: title,
        content: content,
        success(res) {
            callback(res)
        }
    })
}

module.exports = {
    request,
    showToast,
    showLoading,
    showModal
}

微信小程序wx.request,wx.showToast,wx.showLoading,wx.showModal的简易封装

原文:https://www.cnblogs.com/sq652366/p/12912026.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!