在模板中使用if判断不生效
写一个弹出层,然后再页面上做if判断不生效
上代码和图
初始化:
点击按钮触发函数:
模板代码:
<template name="toast"> <view class='toast-out' wx:if="{{is_show}}"> <view class='toast-in'> <span class='iconfont {{iconClass}}'></span> <view class='toast-txt'> {{txt}} </view> </view> </view></template> |
函数代码:
test:function(){ // this.toastShow(this,'登录名不能为空',"icon-suo") console.log('================执行自定义函数') app.toastShow(this,'登录名不能为空',"icon-suo");}, |
app.js中封装的函数
toastShow:function(that,str,icon){ that.setData({ is_show: true, txt: str, iconClass:icon }); setTimeout(function () { //toast消失 that.setData({ is_show: false }); }, 1500); } |
点击按钮,is_show的值变了,但是页面没有效果展示出来,直接注释掉这些的话页面是会有弹出层的
<template name="toast"> <view class='toast-out'> <view class='toast-in'> <span class='iconfont {{iconClass}}'></span> <view class='toast-txt'> {{txt}} </view> </view> </view></template> |
em…新手求解
