(已解决,浏览器问题)点击获取元素下标

来源:3-2 为什么会有 vue3

Zedof

2020-12-18

破案了,我用的是360浏览器打印不出来,用firefox浏览器就好了。

老师您好,这里为什么不能把v-for的index传到点击事件那里?
或者我应该查看vue文档的哪部分获得提示?

<template>
  <div v-for="(item,index) in arr" :key="item">
    <div class="box" @click="click(index)">{{item.name}}{{index}}</div> 
  </div>
</template>

<script>
export default {
  setup() {
    const arr = [{ name: "one" }, { name: "two" }, { name: "three" }];
    const click = (index) => {
      console.log(index);
    };

    return {
      arr,
      click,
    };
  },
};
</script>
写回答

1回答

张轩

2020-12-19

已解决~

0
0

Vue3 + TS 仿知乎专栏企业级项目

带你完成前后端分离复杂项目,率先掌握 vue3 造轮子技能

3074 学习 · 2253 问题

查看课程