wx.request怎么全局封装
发布于 5 年前 作者 rhou 6057 次浏览 来自 问答

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

2 回复

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,

})

}

})

}

可以参考下https://www.jianshu.com/p/ad1e5b581e18

回到顶部