簡體   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