在模板中使用if判断不生效
发布于 6 年前 作者 yangfang 1302 次浏览 来自 问答

写一个弹出层,然后再页面上做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…新手求解

2 回复

麻烦给个相关的代码片段(https://developers.weixin.qq.com/miniprogram/dev/devtools/minicode.html),我们定位下问题

编辑器版本是:v1.01.1711160 再升级之后就打不开编辑器,我也很无奈的,所以选择不升级处理

回到顶部