search

Home  >  Q&A  >  body text

javascript - I get an error when I bind an event in v-for in vue?

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梦2790 days ago711

reply all(2)I'll reply

  • PHPz

    PHPz2017-05-19 10:40:42

    is methods

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

    reply
    0
  • 我想大声告诉你

    我想大声告诉你2017-05-19 10:40:42

    The total method is not defined, the downstairs is correct

    reply
    0
  • Cancelreply