index.wxml
<view class="container"> <view class="usermotto"> <text class="user-motto">{{motto}}</text> 用户名: <input type="text" bindinput="userNameInput"/> 密码: <input type="text" bindinput="userPasswordInput" password="true"/> <button bindtap="logIn">登录</button> </view> </view>
index.js
var app = getApp() Page({ data: { motto: '欢迎登录WXapp', userName:'', userPassword:'', id_token:'',//方便存在本地的locakStorage response:'' //存取返回数据 }, userNameInput:function(e){ this.setData({ userName: e.detail.value }) }, userPasswordInput:function(e){ this.setData({ userPassword: e.detail.value }) console.log(e.detail.value) }, logIn:function(){ var that = this wx.request({ url: 'http://localhost:8000/admin', data: { username: this.data.userName, password: this.data.userPassword, }, method: 'GET', success: function (res) { that.setData({ id_token: res.data.id_token, response:res }) try { wx.setStorageSync('id_token', res.data.id_token) } catch (e) { } wx.navigateTo({ url: '../components/welcome/welcome' }) console.log(res.data); }, fail: function (res) { console.log(res.data); console.log('is failed') } }) } })
尊敬的会员,只需要简单地分享到微信、QQ空间、微薄等,就可以轻松地获得获得下载积分免费下载、发布任务啦,详细见推广规则。