I looped to generate route-link in v-for and wanted to bind an event to it. However, an error was reported saying that the event was undefined. The following is my code
<ul class="card-list">
<li v-for="(url, index) in urls">
<router-link class="linkTo" :to="'/Page' + (index + 1)">
<img @click="total(index)" class="cardWidth" :src="url" alt="">
</router-link>
</li>
</ul>
method: {
total: function (index) {
console.log(index)
}
}
Error message:
Property or method "total" is not defined on the instance but referenced during render. Make sure to declare reactive data properties in the data option.
Uncaught TypeError: _vm.total is not a function
is methods
http://vuejs.org/v2/api/#methods
The total method is not defined, the downstairs is correct