TypechoJoeTheme
2018-04-18
微信小程序的请求方法一直比较复杂,每次调用都要重写一遍,感觉效率很低,于是想简单封装一下,看起来美观一点点。首先可以在小程序默认的utils/文件夹下新建一个common.js类,然后在common.js里写上一些常用的方法。比如封装一个网络请求,可以用这种/*封装Post请求方法 */
function curl_post (url, data, resolve, reject) {
wx.request({
url: url,
data: data,
header: {
//'Content-Type': 'application/json'
'content-type': 'application/x-www-form-urlencoded'
},
method: 'POST',
dataType: 'json',
responseType: 'text',
success: function (res) {
console.log("curl_post成功,返...