Unterschiede
Hier werden die Unterschiede zwischen zwei Versionen angezeigt.
Nächste Überarbeitung | Vorhergehende Überarbeitung | ||
en:modul:m291:learningunits:lu07:theorie:02 [2025/05/05 13:29] – angelegt vdemir | en:modul:m291:learningunits:lu07:theorie:02 [2025/05/05 13:52] (aktuell) – vdemir | ||
---|---|---|---|
Zeile 1: | Zeile 1: | ||
- | ====== LU07b - Methods | + | ====== LU07b - Methods with arguments |
===== Learning ojectives ===== | ===== Learning ojectives ===== | ||
- | - Be able to call existing methods (subroutines) in Vue. | + | - Write own parameterised |
- | - Be able to programme your own methods | + | - Make use of methods |
- | - Be be able to create and use methods | + | |
- | + | ===== Source | |
- | ===== Introduction | + | [[http:// |
- | Actions such as clicking a mouse button can trigger simple actions such as changing colour, but also complex operations, e.g. calculation the VAT(Value added tax). In the latter case, these complex operations are handled using subroutines such as methods. | + | |
===== Introduction to Vue Methods ===== | ===== Introduction to Vue Methods ===== | ||
- | In Vue.js, | + | This lesson is about writing and using methods |
- | + | ||
- | Vue methods | + | |
- | + | ||
- | ===== Example 1: Simple Counter ===== | + | |
- | This example shows how to use a Vue method to increment a counter when a button is clicked. The increment method is called when the button is clicked. It increases the count value by 1 using this.count++. | + | |
+ | ===== Example 1: Method with one parameter ===== | ||
+ | The following example calls a method when pushing a button. This event passes a message to be displayed as an argument to the method. | ||
+ | |||
< | < | ||
<div> | <div> | ||
- | | + | <button @click=" |
- | | + | |
</ | </ | ||
</ | </ | ||
+ | |||
< | < | ||
- | | + | |
- | | + | methods: |
- | | + | |
- | count: 0 | + | |
- | | + | |
- | }, | + | |
- | methods: { | + | |
- | increment() { | + | |
- | this.count++; | + | |
- | } | + | |
} | } | ||
- | }; | + | } |
+ | } | ||
</ | </ | ||
- | ===== Example 2: Greeting a User ===== | + | |
- | This example | + | ===== Example 2: Multiple parameters |
+ | This method-example | ||
< | < | ||
<div> | <div> | ||
- | | + | <button @click=" |
- | | + | |
</ | </ | ||
</ | </ | ||
+ | |||
< | < | ||
export default { | export default { | ||
- | data() { | ||
- | return { | ||
- | name: '' | ||
- | }; | ||
- | }, | ||
methods: { | methods: { | ||
- | | + | |
- | alert(`Hello, | + | alert(`The sum is ${a + b}`); |
} | } | ||
} | } | ||
- | }; | + | } |
</ | </ | ||
- | |||
- | |||
- | |||
- | |||
- | ===== Source ===== | ||
- | [[https:// | ||
- | |||
===== Vocabulary ===== | ===== Vocabulary ===== | ||
^ English ^ German ^ | ^ English ^ German ^ | ||
- | | VAT | Mehrwertsteuer | + | | ... | ... | |
- | | to invoke | + | | ... | ... | |
- | | submission | + | | ... | ... | |
---- | ---- | ||
[[https:// | [[https:// | ||