微信小程序的wx-request请求

news/2024/7/20 0:48:48 标签: 小程序
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();
        }
      }
    })

http://www.niftyadmin.cn/n/861582.html

相关文章

微信小程序使用wx.navigateBack返回时,页面不刷新问题

wx.navigateBack({delta: 1})在js文件中找到这个 onShow: function () {//获取数据 this.gainData() }, 可以刷新页面的数据

微信小程序的点击获取数据,和url路由传值,全局本地存储数据

微信小程序的点击获取数据&#xff0c;和url路由传值&#xff0c;全局本地存储数据 点击获取数据 点击事件的写法bindtap方法名 需要数据的名称 data-xxx{{数据}}//在wxml <van-row gutter"20" class"data" bindtapgetupdateNew data-token"{{it…

微信小程序的wxRequest的请求

微信小程序的wxRequest的请求 可以先在app.js里面把url统一封装好 App({urlData:{URL: url,}, })getRegister:function(event){console.log(event)var url app.urlData.URL /user/regist_phone_uservar random Math.random()wx.request({url: url,data:{phone:this.data.p…

vue打包的时候,全局注释console调试

在开发的时候&#xff0c;我们会用到很多console的调试&#xff0c;在开发完成的时候&#xff0c;又不想一个个去注释&#xff0c;所以在打包的时候可以在build文件夹中找到webpack.prod.conf.js文件中添加以下代码 new UglifyJsPlugin({uglifyOptions: {compress: {warnings: …

js的数组判断属性是否存在,给对象添加一个属性和值,给后端拿到的数组对象添加一个状态值,给数组对象添加一个属性和值

判断属性是否存在 if(shop_id in liveInfo)group_live_gli(){let chat_sid localStorage.getItem(chat_sid)let liveInfo this.liveinfoif(this.chat_type group_live){if(shop_id in liveInfo){let shopid liveInfo.shop_id}else{}}else{}},2.给对象添加一个属性和值 li…

微信小程序中,不允许用户返回上一页的操作

微信小程序中&#xff0c;不允许用户返回上一页的操作 //用wx.redirectTo来做跳转页面wx.redirectTo({url: /pages/index/index })但是用了这个之后会发现小程序左上角会多了一个home的小按钮&#xff0c;可以在onShow中添加wx.hideHomeButton()&#xff0c;即可消除 onShow:…

elementui的图片上传加限制规则并且显示图片在页面,不经过后端

elementui的图片上传并且显示图片在页面&#xff0c;不经过后端 <el-uploadaction"#" refupload1list-type"picture-card":on-change"onChange":limit"1":auto-upload"false":file-list"fileList":http-requ…

子组件调用父组件方法,父组件调用子组件方法,子组件传值给父组件,父组件传值给子组件;兄弟之间传值

子组件调用父组件方法&#xff0c;父组件调用子组件方法&#xff0c;子组件传值给父组件&#xff0c;父组件传值给子组件 子组件调用父组件方法&#xff08;可以多层级调用方法&#xff09;&#xff0c;子组件传值给父组件 //子组件代码 getToParent(){//getParent是父组件的…