I am new to Vue, i want to create some buttons from my data and display their information when clicking the button. The object 'pets' has two keys: id and info. (My data is larger and my code more complicated, i was trying to simplify it here.)
data() {
return {
selectedpet: undefined,
message: undefined,
pets : [
{
id: 1,
info: "yellow"
},
{
id: 2,
info: "brown"
},
{
id: 3,
info:"huge"
}
]
}
}
And I created some buttons by the data with the 'id' displayed on the buttons, and the variable 'selectedpet' will record the clicked button:
<div v-for="pet in pets :key="pet.id">
<button @click="selectedpet = pet">
<i>{{pet.id}}</i>
</button>
What i need to do is to create a div, which text will display the 'info' of the clicked button. How can i set the message to the 'info' of the click button?
<div id="printselectedpet">Selected pet: {{ message }}</div>