微信小程序wx.request内调用setData方法
生活随笔
收集整理的這篇文章主要介紹了
微信小程序wx.request内调用setData方法
小編覺得挺不錯的,現(xiàn)在分享給大家,幫大家做個參考.
附上源碼
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發(fā)生了submit事件,攜帶數(shù)據(jù)為:', e.detail.value)self=thiswx.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發(fā)生了reset事件')} })總結
以上是生活随笔為你收集整理的微信小程序wx.request内调用setData方法的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 电脑怎么设置u盘做系统 设置U盘装系统教
- 下一篇: Python批量剪裁图片