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:""})
}
},
},
})
微信小程序实现数据监听
最新推荐文章于 2024-07-25 16:09:55 发布