微信小程序的用户登录

过程

当你点登录按钮的时候会跳转到teachers的页面上。首先你要发起请求用wx.request,调用接口,得到他的username和password,用wx.setStorage将数据存储在本地缓存中,用wx.redirectTo进行页面的跳转。

登录的页面


login.wxml代码

<!--pages/login/login.wxml-->
<form bindsubmit='formSubmit'>
  <view class="section">
    <view class="section__title">学号:</view>
    <input name="no" type="number" placeholder="请输入学号"  />
  </view>
  <view class="section">
    <view class="section__title">密码:</view>
    <input name="pwd" type="number" password='true' placeholder="请输入密码"  />
  </view>
  <view class="btn-area">
    <button form-type="submit" type='primary'>登录</button>
  </view>
</form>

login.js代码

formSubmit(e){
    // console.log(e)
    wx.request({
      url: xxx, //仅为示例,并非真实的接口地址
      data: {
        username: e.detail.value.no,
        password: e.detail.value.pwd
      },
      header: {
        'content-type': 'application/json' // 默认值
      },
      success: function (res) {
        console.log(res.data)
        wx.setStorage({
          key: "student",
          data: res.data
        });
        wx.redirectTo({
          url: "../teachers/teachers"
        })
      }
    })
  }

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值