Reputation: 2018
So I got this buttons and an input. Whenever I click one of each button, I want the arrow to appear in the answer field, for example If i click twice left arrow and twice right arrow, I want 4 of them to be in my input. How can I achieve this?
<button class="arrow_button">←</button>
<button class="arrow_button">↑</button>
<button class="arrow_button">↓</button>
<button class="arrow_button">→</button>
<input v-model="passwordAnswer" placeholder="Password" />
Upvotes: 0
Views: 789
Reputation: 36
You need to add a click handler to all of your buttons, like this:
<button class="arrow_button" @click="passwordAnswer += '←'">←</button>
<button class="arrow_button" @click="passwordAnswer += '↑'">↑</button>
<button class="arrow_button" @click="passwordAnswer += '↓'">↓</button>
<button class="arrow_button" @click="passwordAnswer += '→'">→</button>
<input v-model="passwordAnswer" placeholder="Password" />
To avoid duplicates you can use v-for
and iterate over an array of your options (arrows) to create the buttons.
Upvotes: 2