微信小程序的wx-request请求

var that = this
    var url = url
    var random = Math.random()
    if(!this.data.phone || !this.data.password){
      wx.showToast({
        title: '不能为空',
        icon: 'none',
        duration: 1000,
        mask:true
    })
    wx.hideToast();
    return
    }
    wx.request({
      url: url,
      data:{
        phone:this.data.phone,
        pwd:this.data.password,
        random:random
      },
      header: {
        'content-type': 'application/json' // 默认值
      },
      success: function(res) {
        console.log(res.data);
        // that.setData({teachers:res.data});
        var data  = res.data
        if(data.ret){
          wx.showToast({
            title: '登录成功',
            icon: 'succes',
            duration: 1000,
            mask:true
        })
        wx.hideToast();
        var app = getApp();
        app.appData.userInfo = {"user_id":res.data.user_id,"s_id":res.data.s_id};
        wx.setStorage({
          key: 'userInfo',
          data: JSON.stringify(res.data)
        })
          wx.navigateTo({ url: '/pages/index/index',})
        }else if(res.data.msg == 'phone is error'){
          wx.showToast({
            title: '手机号码错误',
            icon: 'none',
            duration: 1000,
            mask:true
        })
        wx.hideToast();
      }else if(res.data.msg == 'pwd is error'){
          wx.showToast({
            title: '密码错误',
            icon: 'none',
            duration: 1000,
            mask:true
        })
        wx.hideToast();
        }else if(res.data.msg == 'phone unregist now!'){
          wx.showToast({
            title: '该账号还没有注册',
            icon: 'none',
            duration: 1000,
            mask:true
        })
        wx.hideToast();
        }else{
          wx.showToast({
            title: '登录失败',
            icon: 'none',
            duration: 1000,
            mask:true
        })
        wx.hideToast();
        }
      }
    })
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

一介青烟小生

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值