1.wxml:
<view>账号: <input placeholder="请输入账号" model:value="{{account}}" style="background-color: rgb(202, 173, 173);" type="text" /> 密码: <input placeholder="请输入密码" model:value="{{password}}" style="background-color: rgb(202, 173, 173);" type="password" /> <button style="margin-top: 20px;" bindtap="request">请求接口</button> </view>
2.js:
data: { account: 'admin', password: '123456', data:[] } request(e) { let item = this wx.request({ url: 'http://*********/role/user/login', data: { account: this.data.account, password: this.data.password }, header: { 'content-type': 'application/json' // 默认值 }, method: 'GET', success: function (res) { // console.log(res.data.data.userinfo.roles); item.setData({ data: res.data.data.userinfo.roles }) if (res.data.code == 1) { wx.showToast({ title: res.data.msg, }) } else { wx.showToast({ title: res.data.msg, }) } } }) }