繁体   English   中英

dom的孩子(如果未在测试中进行评估)

[英]Children of dom-if not evaluated in test

在下面的示例中进行单元测试时,永远不会显示该段落。 我有检查showContent是否为true的测试,该测试成功了,但是当我打印出unittest中的元素时,模板立即关闭。 我已经尝试过将组件的打印包装得很整齐,但这无济于事。 为什么不评估dom?

 <template is='dom-if' if='{{showContent}}'>
            <p>hello world</p>
        </template>

您应该具有以下内容:

    showContent:{
      type: Boolean,
      computed: '_computeshowContent(parameter)',
      value: null
    }
    _computeshowContent(parameter){
      if (parameter === 'something'){
        return true;
      }else{
        return false;
      }
    }

您的OP中没有足够的代码来提供正确的答案,但是我想您可能将变量showContent设置为错误。 您应该使用this.set('showContent', true)而不是this.showContent = true 前者向变量已更新的所有元素发送事件。

使用

[英]Using <template is=“dom-if” with a condition

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM