标签:fail UI 失败 ram nba head message method port
https://blog.csdn.net/qq_35713752/article/details/78109084
// url:网络请求的url method:网络请求方式 data:请求参数 message:提示信息 success:成功的回调函数 fail:失败的回调
//pages/utils/util
function request(url, method, data, message, success, fail) {
wx.showNavigationBarLoading()
if (message != "") {
wx.showLoading({
title: message,
})
}
wx.request({
url: url,
data: data,
header: {
‘content-type‘: ‘application/x-www-form-urlencoded‘
},
method: method,
success: function (res) {
wx.hideNavigationBarLoading()
if (message != "") {
wx.hideLoading()
}
if (res.statusCode == 200) {
success(res.data)
} else {
console.log("请求成功,返回信息:" + res.statusCode)
}
},
fail: function (err) {
wx.hideNavigationBarLoading()
if (message != "") {
wx.hideLoading()
}
console.log(‘请求失败:‘+err)
},
})
}
module.exports = {
request: request
}
//pages/index/index
var util = require("../../utils/util.js")
Page({
data: {
list_data:‘‘,
params: { id: 1 }
},
onLoad: function (options) {
var that = this
util.request(‘https://127.0.0.1/Index/wellcome‘, ‘get‘, this.data.params , ‘正在加载数据‘, function (res) {
console.log("返回的信息:"+res)
that.setData({
list_data:res
})
}, function (err) {
wx.showToast({
title: ‘加载数据失败‘,
})
})
}
})
//pages/index/wxml
<view>{{list_data}}</view>
标签:fail UI 失败 ram nba head message method port
原文地址:https://www.cnblogs.com/wcLT/p/9055502.html