<div v-for="(grp,idx) in vm">
<button onclick="addPlant(idx)">
.......
</button>
</div>
addPlant() is a javascript function and not a VueJS method.
How can I pass the idx
value to the javascript method now?
<div v-for="(grp,idx) in vm">
<button onclick="addPlant(idx)">
.......
</button>
</div>
addPlant() is a javascript function and not a VueJS method.
How can I pass the idx
value to the javascript method now?
Create a Vue method calling the javascript function
...
You can't reference the Vue template variables from a vanilla javascript
onclick
handler like you're trying to do.You should pass the index value to a Vue
@click
handler and call the vanilla javascript method from there:If we go to be limited to your specific use case we could assign
index
todata-label
attribute (which is bound toindex
) and passthis.getAttribute('data-label')
as parameter,this
refers to the Html element not to the Vue instance or component: