我在vue中的v-for里绑定事件报错?

我在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
阅读 3.4k
2 个回答

没有定义total这个方法,楼下正确

撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进
推荐问题