button请求loading效果
//当loading="ture"是处于loading状态,为false时消失,所有先给个不定值{{loading}},具体的值在js中设置
<button type="primary" formType="submit" loading="{{loading}}">申请</button>
//下面是请求的js代码
formSubmit: function (e) {
var self = this
var userName = wx.getStorageSync('userName');
console.log('卡号:', userName)
//请求开始设为ture
self.setData({
loading: true
})
if (e.detail.value.phone.length != 11) {
wx.showToast({
title: '请输入11位手机号码!',
icon: 'loading',
duration: 1500
})
//让loading状态消失
self.setData({
loading: false
})
return false;
}
var that = this;
var formData = e.detail.value;
wx.request({
url: 'https://www.vilyun.com/Home/door/visitordoors',
data: {
phone: e.detail.value.phone,
cardno: userName
},
header: {
'Content-Type': 'application/json'
},
success: function (res) {
if(res.data.status=='yes'){
wx.showToast({
title: '请求成功',
icon: 'success',
mask: true,
duration: 1500
})
}else{
wx.showToast({
title: res.data.msg,
icon: 'loading',
duration: 2000
})
}
self.setData({
loading: false
})
console.log(res.data)
}
})
},