Unterschiede
Hier werden die Unterschiede zwischen zwei Versionen angezeigt.
Beide Seiten der vorigen Revision Vorhergehende Überarbeitung Nächste Überarbeitung | Vorhergehende Überarbeitung | ||
en:modul:m291:learningunits:lu05:theorie:03 [2025/02/28 13:10] – vdemir | en:modul:m291:learningunits:lu05:theorie:03 [2025/03/14 12:36] (aktuell) – vdemir | ||
---|---|---|---|
Zeile 1: | Zeile 1: | ||
- | ====== LU05c - v-if - TBD ====== | + | ====== LU05c - v-if ====== |
===== Learning ojectives ===== | ===== Learning ojectives ===== | ||
- | - ??? | + | - I can explain what the directive v-if fulfil within the DOM. |
- | - | + | - I can name the three v-if variants that are possible in principle. |
+ | - I can apply v-if to specific examples. | ||
+ | |||
+ | ===== Sources ===== | ||
+ | * [[https:// | ||
+ | * [[https:// | ||
+ | |||
===== Introduction ==== | ===== Introduction ==== | ||
- | ??? | + | The v-if directive in Vue.js is used to conditionally render elements in the DOM. If the condition provided in the //v-if// evaluates to true, the element is rendered; otherwise, it is removed from the DOM entirely. This makes v-if a powerful tool for controlling the visibility of elements based on dynamic data. |
- | ===== TDB ===== | + | <div id=" |
+ | <button @click=" | ||
+ | <p v-if=" | ||
+ | </ | ||
+ | < | ||
+ | new Vue({ | ||
+ | el: '# | ||
+ | data: { | ||
+ | isVisible: true | ||
+ | }, | ||
+ | methods: { | ||
+ | toggleMessage() { this.isVisible | ||
+ | } | ||
+ | } | ||
+ | }); | ||
+ | </ | ||
+ | In this example above, the paragraph element (<p>) is conditionally displayed based on the value of the // | ||
+ | ===== Variants ===== | ||
+ | There are basically three variants of // | ||
+ | - v-if | ||
+ | - v-else-if | ||
+ | - v-else | ||
+ | |||
+ | ==== 1. v-if ==== | ||
+ | * Used to conditionally render an element based on whether the condition evaluates to //true//. | ||
+ | * If the condition is //false//, the element is completely removed from the DOM. | ||
+ | |||
+ | **Example: | ||
+ | | ||
+ | <p v-if=" | ||
+ | | ||
+ | ==== 2. v-else-if ==== | ||
+ | * Used to create an additional condition in conjunction with //v-if//. | ||
+ | * orks like an //else-if// statement in programming, | ||
+ | |||
+ | <p v-if=" | ||
+ | <p v-else-if=" | ||
+ | |||
+ | ==== 3. v-else ==== | ||
+ | * Provides a fallback for when none of the //v-if// or // | ||
+ | * It does not accept any condition and must directly follow //v-if// or // | ||
+ | |||
+ | <p v-if=" | ||
+ | <p v-else-if=" | ||
+ | <p v-else> | ||
+ | |||
+ | ===== Additional Material ===== | ||
+ | |||
+ | {{: | ||
===== Vocabulary ===== | ===== Vocabulary ===== | ||
+ | |||
^ English ^ German ^ | ^ English ^ German ^ | ||
- | | ...| ... | | + | | to render |
+ | | conjunction | verbindung | ||
---- | ---- | ||
[[https:// | [[https:// | ||