繁体   English   中英

Lightning Web 组件 IF 指令是否支持多个条件?

[英]Does Lightning Web Component IF Directive support multiple conditions?

嗨,我是 LWC 世界及其语法的新手。 我想问一下,LWC 是否支持单个语句中的多个条件?

前任:

<template if:true={condition1 == 'value1' && condition2 == 'value2'}></template>

在单行语句上使用多个条件时出错。

或者应该采用以下方法

html - <template if:true={validateCondition}></template>
class js file - get validateCondition() { return (condition1 == 'value1' && condition2 == 'value2');}

或者必须使用嵌套条件

<template if:true={condition1 == 'value1'}>
  <template if:true={condition2 == 'value2'}>
  </template>
</template>

当前使用上述语句

选项 2. 保持 html 干净。 显示/隐藏页面部分的决定是您业务逻辑的一部分,应与其他计算一起保存在 JS 中。 这也使它可测试。 我认为您甚至无法执行选项 3,我希望它在编译时失败?

您不能在这些或任何计算中使用公式,只能使用直接属性和 getter。 https://developer.salesforce.com/docs/component-library/documentation/en/lwc/lwc.reference_directives

迁移指南也可能有所帮助: https : //developer.salesforce.com/docs/component-library/documentation/en/lwc/lwc.migrate_expressions

这个答案也很酷: https : //salesforce.stackexchange.com/q/249293/799

暂无
暂无

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

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