Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

我在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

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
505 views
Welcome To Ask or Share your Answers For Others

1 Answer


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...