Answer the question
In order to leave comments, you need to log in
Why is the button click handler not working in the generated list component?
Good afternoon, comrades! I started to learn vue.js and the following question arose
. There is such a markup with a list of rooms-list:
<div class="col s4">
<a class="collection-header"><h4>Rooms List</h4></a>
<ul id = "rooms-list" class="collection" v-html="rooms">
</ul>
</div>
if(msg.Raw.isCreated == true)
{
self.rooms += '<li class="collection-item"><div>'+msg.Raw.roomName+'<button v-on:click="enterRoom(\''+msg.Raw.roomName+'\')"></button></div>';
}
Answer the question
In order to leave comments, you need to log in
Don't use html in lists...
<template>
<div class="col s4">
<a class="collection-header"><h4>Rooms List</h4></a>
<ul id = "rooms-list" class="collection">
<li v-for="(room, index) in rooms" :key="index" @click="myMethod(room)">{{room}}</li>
</ul>
</div>
</template>
<script>
export default {
name: 'qqqq',
data() {
return {
rooms: [
'room1',
'room2',
'room3',
'room4',
]
}
},
methods: {
addRoom(name) {
this.rooms.push(name);
}
}
}
</script>
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question