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:03] – 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 ====== | ||
| + | * [[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; | + | |
| } | } | ||
| - | } | + | }; |
| - | }); | + | |
| </ | </ | ||
| + | **Explanation: | ||
| + | * The v-show=" | ||
| + | * Clicking the button toggles isVisible between true and false. | ||
| + | * Instead of removing the element from the DOM, Vue modifies its display property. | ||
| - | In this example above, the paragraph element (<p>) is conditionally displayed based on the value of the // | + | ===== v-if VS v-show ===== |
| + | Both, v-if and v-show are conditional rendering, but unlike v-if, the v-show directive **only** make the object of concern **invisible**, | ||
| - | ===== TDB ===== | + | ===== Demonstration |
| + | [[https:// | ||
| + | * **v-show:** Hides only an object, it is still accessible for fold-in or fold-out | ||
| + | * **v-if:** The object of concern is no longer existing, as it was destroyed from the HTML-DOM. | ||
| + | |||
| + | |||
| + | ^Feature ^v-if ^v-show ^ | ||
| + | | DOM Behavior | Completely adds/ | ||
| + | | Performance | Better for infrequent changes (expensive re-rendering) | Better for frequent toggling (faster updates) | | ||
| + | | Usage Case | When elements are rarely shown/ | ||
| + | |||
| ===== Vocabulary ===== | ===== Vocabulary ===== | ||
| ^ English ^ German ^ | ^ English ^ German ^ | ||
| - | | ...| ... | | + | | conditionally |
| + | | to fold in/out | einklppen/ | ||
| ---- | ---- | ||
| [[https:// | [[https:// | ||