I'm v-for some buttons from some data, these data contain callback that I want to bind to <button />.
I know some of those data have no callback, so I wrote this
<button @click="item.click || (() => {})"></button>
However, this line is not working as I expected, now, all my buttons' click event is not doing things anymore.
Please see this minimum example
<template>
<div>
<div v-for="(item, itemIndex) in data" :key="itemIndex">
<button @click="item.click || (() => {})">Click {{ itemIndex }}</button>
</div>
</div>
</template>
<script>
export default {
data() {
return {
data: [
{
click: () => {
alert("First Item");
},
},
{
// Empty Object
},
],
};
},
};
</script>
What should I do to prevent empty callbacks?
Here is my CodeSandbox
(Click 0 is not working)
