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:04 [2025/01/27 12:33] – vdemir | en:modul:m291:learningunits:lu05:theorie:04 [2025/03/14 13:46] (aktuell) – vdemir | ||
---|---|---|---|
Zeile 1: | Zeile 1: | ||
- | ====== LU05d - v-if - TBD ====== | + | ====== LU05d - v-show ====== |
===== Learning ojectives ===== | ===== Learning ojectives ===== | ||
- | - I can explain what function | + | - I can explain what directive |
- | - I can name the three v-if variants that are possible in principle. | + | - I can prove the visibility of objects using v-show. |
- | - I can apply v-if to specific examples. | + | - I can use the v-show directive. |
- | ===== Sources ===== | + | ====== Sources |
- | * [[https:// | + | * [[https:// |
- | * [[https:// | + | * [[https:// |
===== Introduction ==== | ===== Introduction ==== | ||
- | The v-if directive in Vue.js is used to conditionally | + | The v-show directive in Vue.js is used to conditionally |
+ | |||
+ | The syntax is simple: isVisible controls | ||
+ | |||
+ | <div v-show=" | ||
+ | |||
+ | ===== Example ===== | ||
+ | < | ||
+ | < | ||
+ | <button @click=" | ||
+ | Toggle Message | ||
+ | </ | ||
+ | <p v-show=" | ||
+ | </ | ||
+ | </ | ||
- | <div id=" | ||
- | <button @click=" | ||
- | <p v-if=" | ||
- | </ | ||
< | < | ||
- | | + | |
- | el: '# | + | data() { |
- | data: { | + | |
- | isVisible: true | + | |
- | }, | + | }; |
- | methods: { | + | |
- | toggleMessage() { this.isVisible = !this.isVisible; | + | |
} | } | ||
- | } | + | }; |
- | }); | + | |
</ | </ | ||
- | In this example above, | + | **Explanation: |
+ | * The v-show=" | ||
+ | * Clicking the button toggles | ||
+ | * Instead of removing | ||
- | ===== Variants | + | ===== v-if VS v-show |
- | There are basically three variants of //v-if//: | + | Both, v-if and v-show are conditional rendering, but unlike |
- | | + | |
- | - v-else-of | + | |
- | - v-else | + | |
- | ==== 1. v-if ==== | + | ===== Demonstration ===== |
- | * 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:** | + | [[https:// |
- | + | ||
- | <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, | + | |
- | | + | |
- | | + | |
- | ==== 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=" | + | ^Feature ^v-if ^v-show ^ |
- | <p v-else-if=" | + | | DOM Behavior | Completely adds/removes elements from the DOM | Only toggles the display property (keeps elements in the DOM) | |
- | <p v-else> | + | | Performance | Better for infrequent changes (expensive re-rendering) | Better for frequent toggling (faster updates) | |
- | + | | Usage Case | When elements are rarely shown/ | |
- | ===== Additional Material ===== | + | |
- | {{: | + | |
===== Vocabulary ===== | ===== Vocabulary ===== | ||
^ English ^ German ^ | ^ English ^ German ^ | ||
- | | to render | + | | conditionally |
- | | conjunction | + | | to fold in/ |
---- | ---- | ||
[[https:// | [[https:// | ||