if 语句:用于当指定条件为真时执行代码块。 if...else 语句:当条件为真时执行一个代码块,否则执行另一个代码块。 if...else if...else 语句:用于在多个条件之间进行选择。 switch 语句:用于在多个条件中选择一个来执行相应的代码块。 示例代码 if 语句 代码语言:txt 复制let...
console.log("用户名为:"+this.data.userName) if(this.data.userName==""){ wx.showToast({ title: '请填写姓名', duration: 2000 }) } else if(this.data.school==""){ wx.showToast({ title: '请填写学校', duration: 2000 }) } else if(this.data.department==""){ wx.showToast({ title:...
getsttag(app.globalData.shitangname) ///查询选择的食堂是否关闭了当日报餐功能 if (app.globalData.sttag == '1') { wx.showToast( { icon:'error', title:'已关闭当日报餐', }) return }else {console.log("打印测试获取的数据",'000000')} } 这个get()在执行的时候,先if判断 后再执行this. ...
1.wx:if 在小程序中,使用wx:if="{{condition}}"来判断是否需要渲染该代码块: 也可以用wx:elif和wx:else来添加else判断: 实例如下: 1.在js文件中定义一个type data:{ type:1 }, 1. 2. 3. 此时虚拟页面上显示的就是:女 2.结合< block >使用 wx : if 如果要一次性控制多个组件的展示与隐藏,可以...
if (res.confirm) { that.setData({ name: '李四' }, function () { wx.showToast({ title: '操作完成', duration: 700 }); }); } else if (res.cancel) { console.log('用户点击取消'); } } }); } }); 1. 2. 3. 4. 5.
if (res.confirm) { console.log('用户点击确定') } else if (res.cancel) { console.log('用户点击取消') } } }) 1、基本配置 wx.showModal方法有多个配置项,包括title、content、showCancel、cancelText、confirmText等,可以根据需要进行自定义。比如: ...
}elseif(this.data.canIUse){//由于 getUserInfo 是网络请求,可能会在 Page.onLoad 之后才返回//所以此处加入 callback 以防止这种情况app.userInfoReadyCallback = res =>{this.setData({ userInfo: res.userInfo, hasUserInfo:true}) } }else{//在没有 open-type=getUserInfo 版本的兼容处理wx.getUserInfo...
console.log('缓存的数据', user, userInfo)if((user && user.userId) ||this.globalData.userInfo.nickName) { wx.showTabBar(); }else{ wx.hideTabBar() }if((!user.openid || (user.expires_in || Date.now()) < (Date.now() + 600)) && (!userInfo.nickName)) { ...
if (!(/^[1-9]\d{5}(?!\d)/.test(num))) { return false; }else{ return true; } }; module.exports = { phone : phone, sfzcard : sfzcard, number : number, ctext : ctext, mail : mail, pcode : pcode, } 2.在index.wxml使用 ...
index.wxs vartimeFormat=function(time){varlastDate=getDate(time);console.log(lastDate);varlastTime=lastDate.getTime()/1000;varnowDate=getDate();varnowTime=nowDate.getTime()/1000;vartimeStamp=nowTime-lastTime;vartimeStr="";if(timeStamp<60){timeStr="刚刚";}elseif(timeStamp>=60&&timeStamp...