微信小程序wx.request,wx.showToast,wx.showLoading,wx.showModal的简易封装
Posted 午夜白雪
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了微信小程序wx.request,wx.showToast,wx.showLoading,wx.showModal的简易封装相关的知识,希望对你有一定的参考价值。
/**
* 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的简易封装的主要内容,如果未能解决你的问题,请参考以下文章