doInsert: function (e) { console.log( 'form发生了submit事件,携带数据为:' , e.detail.value) var name = e.detail.value.name; var id = e.detail.value.id; var password = e.detail.value.password; var gender = e.detail.value.gender; var phone = e.detail.value.phone; var postbox = e.detail.value.postbox; var power = e.detail.value.power; if (power){ power = 0 }else{ power = 1 } var that = this; if (name.length == 0 || id.length == 0 || password.length == 0 ) { wx.showToast({ title: '姓名、编号、密码不能为空!' , icon: 'none' , duration: 500 }) }else{ wx.request({ url: 'http://www.test.com/insert.php' , data: { name: name, id: id, password: password, gender: gender, phone: phone, postbox: postbox, power: power }, header: { 'content-type' : 'applicationjson' }, success: function (res) { console.log(res.data); if (res.data == 1 ){ wx.showToast({ title: '添加成功' , icon: 'success' , duration: 1000 }); }else{ wx.showToast({ title: '添加失败,请重新添加' , icon: 'none' , duration: 500 }); } that.setData({ name: '' , id: '' , password: '' , gender: '' , phone: '' , postbox: '' , }) } }) } }, |
能请问一下大佬们,我这样写为什么提交过后不能清空页面数据呀?十分感谢!!!
感觉你代码可以简化好多地方,你这样你看下 AppData里是否清空了,至于页面上input等 没清空 你需要看下是否都绑定了value