我在v-for裡面循環產生route-link,想給他綁定一個事件,結果報錯說事件未定義,下面是我的程式碼
<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)
}
}
報錯訊息:
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
是 methods
http://vuejs.org/v2/api/#methods
沒有定義total這個方法,樓下正確