add an input field

This commit is contained in:
Andreas Zweili 2021-01-18 18:06:18 +01:00
parent bee75dd9fa
commit c9f6b1af57
2 changed files with 6 additions and 0 deletions

View File

@ -2,9 +2,13 @@ const app = Vue.createApp({
data() { data() {
return { return {
counter: 0, counter: 0,
name: "",
}; };
}, },
methods: { methods: {
setName(event) {
this.name = event.target.value;
},
increaseCounter(inputNumber) { increaseCounter(inputNumber) {
this.counter = this.counter + inputNumber; this.counter = this.counter + inputNumber;
}, },

View File

@ -20,6 +20,8 @@
<button v-on:click="increaseCounter(10)">Add 10</button> <button v-on:click="increaseCounter(10)">Add 10</button>
<button v-on:click="decreaseCounter(5)">Reduce 5</button> <button v-on:click="decreaseCounter(5)">Reduce 5</button>
<p>Result: {{ counter }}</p> <p>Result: {{ counter }}</p>
<input type="text" v-on:input="setName">
<p>Your Name: {{name}}</p>
</section> </section>
</body> </body>