wx.request怎么全局封装

发布于 7 年前作者 rhou6161 次浏览最后编辑 7 年前来自 ask

求一个wx.request全局封装的代码

2 回复
wanli
wanli1 楼6 年前

function request(url, data, method,  callback) {

if (load == 1) {

wx.showLoading({

mask: true,

title: ‘加载中’

})

}

wx.request({

url: url,

data: data,

header: {

“content-type”: “application/x-www-form-urlencoded;charset=utf-8”

},

method: method,

success: function (res) {

callback(res)

},

fail: function (res) {

wx.showToast({

title: “网络连接超时”,

icon: ‘none’,

duration: 3000,

})

}

})

}

ecui
ecui2 楼5 年前