微信小程序实现数据监听

Component({
  properties: {
    // 这里定义了innerText属性,属性值可以在组件使用时指定
  },
  data: {
    // 这里是一些组件内部数据
    //content: 'sdcedc', //主件的数据显示权比behavior高
    src:"/image/register-image/a.jpg",
    ok:false,
    no:false,
    pswOk:false,
    pswNo:false,
    disabled:'true',
    text: '',
  },
 methods:{
 // 验证电话号码
 telChange:function(){
  let tel=this.data.tel;
  if(tel.length==11){
    let str = /^1[34578]\d{9}$/;
  if (str.test(tel)) {
    this.setData({ok:true});
    this.setData({no:false})
  } else {
    wx.showToast({
      title: '手机号不正确',
      icon: 'none'
    })
    this.setData({no:false});
  }
  }else{
    this.setData({ok:false});
    this.setData({no:true});
  }
},
//验证密码:长度大于6
  pswChange:function(){
    let psw=this.data.psw;
    if(psw.length>6){
      this.setData({pswOk:true});
      this.setData({pswNo:false})
    } else {
      wx.showToast({
        title: '密码长度至少为6位',
        icon: 'none'
      })
      this.setData({pswNo:true});
      this.setData({pswOk:false});
    }
  },
  observers:{ //观察者:属性监听
    'ok,pswOk'(ok,pswOk){
      if(ok&&pswOk){
        this.setData({disabled:""})
      }
    },
  },

})

  • 0
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值