微信小程序wx.request,wx.showToast,wx.showLoading,wx.showModal的简易封装
时间:2020-05-18 18:59:10
收藏:0
阅读:104
/**
* 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
}
评论(0)