3👍
✅
Update: based on your need to use it, this is clearly an X-Y problem. You should be using computed properties instead:
computed: {
filteredSharesByCount: function() {
return this.shares.filter(share => share.count > 0);
}
}
You can then reference it as such in your template:
Outdated answer:
The index is accessible as the second optional argument in the v-for
binding:
v-for
also supports an optional second argument for the index of the current item.
ie:
<div v-for="(share, idx) in sharesPurchased(shares)" :key="share">
Then, within the loop you can simply use idx
if you want a method to have access to the index.
Source:stackexchange.com