附上源码
login.wxml文件
<!--pages/login/login.wxml-->
<form bindsubmit="formSubmit" bindreset="formReset">
<view class="page-section">
<view class="weui-cells__title">用户名</view>
<view class="weui-cells weui-cells_after-title">
<view class="weui-cell weui-cell_input">
<input class="weui-input" name="username" maxlength="32" placeholder="在此输入用户名" />
</view>
</view>
<view class="weui-cells__title">密码</view>
<view class="weui-cells weui-cells_after-title">
<view class="weui-cell weui-cell_input">
<input class="weui-input" name="password" maxlength="32" placeholder="在此输入密码" />
</view>
</view>
</view>
<view class="btn-area">
<button formType="submit">提交</button>
<button formType="reset">Reset</button>
</view>
<p>{{result}}</p>
</form>
login.js文件
//index.js
Page({
data: {
result: 'qwerty'
},
onLoad: function() {
console.log("this is login page")
console.log(this.data.result)
},
formSubmit: function (e) {
console.log('form发生了submit事件,携带数据为:', e.detail.value)
self=this
wx.request({
url:'https://chenth.net/login_wx',
data:{
username:e.detail.value.username,
password:e.detail.value.password
},
method:'POST',
header:{
'content-type':'application/json'
},
//self=this,
success:function(res){
console.log("--------chenth success--------");
console.log(res.data);
self.setData({
result: res.data
})
},
fail:function(res){
console.log("--------chenth fail--------");
self.setData({
result: res.data
})
}
})
},
formReset: function () {
console.log('form发生了reset事件')
}
})