I am using Vue and have:
<tr v-for="(blabla, index) in data">
<td>{{ blabla.id }}</td>
<td>{{ blabla.username }}</td>
<td>{{ blabla.name }}</td>
<td>
<router-link
:to="{ name: 'name', params: { blabla: blabla.id } }"
class="mdl-button mdl-js-button mdl-button--raised mdl-js-ripple-effect mdl-button--accent"
>
Details
</router-link>
</td>
</tr>
How can I make the whole row clickable, not just the button that has the router link?
Add a click listener on the tr
and change the route programmatically:
<tr v-for="(blabla, index) in data" @click="goToBlabla(blabla.id)">
<td>{{ blabla.id }}</td>
<td>{{ blabla.username }}</td>
<td>{{ blabla.name }}</td>
<td>
<a class="mdl-button mdl-js-button mdl-button--raised mdl-js-ripple-effect mdl-button--accent">
Details
</a>
</td>
</tr>
methods: {
goToBlabla(id) {
this.$router.push({ name: 'name', params: { blabla: id } });
}
}
Alternately, you could put the v-for
on a <router-link>
with the tag
property set to tr
:
<router-link
v-for="(blabla, index) in data"
:to="{ name: 'name', params: { blabla: blabla.id } }"
tag="tr"
>
<td>{{ blabla.id }}</td>
<td>{{ blabla.username }}</td>
<td>{{ blabla.name }}</td>
<td>
<a class="mdl-button mdl-js-button mdl-button--raised mdl-js-ripple-effect mdl-button--accent">
Details
</a>
</td>
</router-link>
Specifying the tag as tr
will render the component as a tr
element.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With