/**
* 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的简易封装