LU07c - Cascading methods - TBD

  1. Write own parameterised methods.
  2. Make use of methods which expects parameters.

This lesson is about writing and using methods which can process parameters. These parameters are called arguments of a method. Parametrisided methods enable web-application to behave more dynamic and user-friendly.

The following example calls a method when pushing a button. This event passes a message to be displayed as an argument to the method.

<template>

  <div>
    <button @click="sayHello('Alice')">Greet Alice</button>
  </div>
</template>
<script>
export default {
  methods: {
    sayHello(name) {
      alert(`Hello, ${name}!`);
    }
  } 
}
</script>

This method-example has two arguments, and is supposed to calculate the sum of two numnbers. The result will be displayed in a alert-box.

<template>
  <div>
    <button @click="addNumbers(5, 3)">Add 5 + 3</button>
  </div>
</template>
<script>
  export default {
    methods: {
      addNumbers(a, b) {
        alert(`The sum is ${a + b}`);
      }
    }
  } 
</script>
English German

Volkan Demir

  • en/modul/m291/learningunits/lu07/theorie/03.txt
  • Zuletzt geändert: 2025/05/09 09:31
  • von vdemir