javascript - I get an error when I bind an event in v-for in vue?
过去多啦不再A梦
过去多啦不再A梦 2017-05-19 10:38:42
0
2
685

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
过去多啦不再A梦
过去多啦不再A梦

reply all(2)
PHPzhong

is methods

http://vuejs.org/v2/api/#methods

我想大声告诉你

The total method is not defined, the downstairs is correct

Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template