我有一个像这样的v形数据表

// template
<v-data-table
        :headers="headers"
        :items="visitors"
        :search="search"
        item-key="name"
        class="elevation-1"
        @click:row="(item) => clickRow(item.caseId)"
      >
</v-data-table>

//script
clickRow(id){
      this.$router.push({name: "VisitDetails", params: {id: id}});
    },

每当用户单击一行中的任意位置时,我希望获得一个项目(一行)的caseId属性,并将该caseId作为路由参数移动到另一个页面.这不管用.我该怎么解决这个问题?非常感谢.

推荐答案

the docs开始:

"This event provides 2 arguments: the first is the item data that was clicked and the second is the other related data provided by the item slot."

也就是说

@click:row="(item) => clickRow(item.caseId)" ❌ 

应该是:

@click:row="(_, item) => clickRow(item.caseId)" ✅

(其中_是单击的单元格数据,以备需要).


我倾向于只指定处理程序:

@click:row="onRowClick"

并管理处理程序中的参数:

methods: {
  onRowClick(cellData, item) {
    // go wild...
  }
}

  1. 总是阅读文档
  2. console.log()是你的朋友.
  3. When you feel lazy, (like I do, most times), skip step 1 and power up step 2.
    Spread and log all arguments:
@click:row="onRowClick"
 ...
 methods: {
   onRowClick(...args) {
     // this will log all arguments, as array
     console.log(args);
   }
 }

Vue.js相关问答推荐

复选框列未在vutify中排序

如何在 Vuetify 2 中的轮播项目上放置 href 属性?

使用项目和字段,列跨度为 2 的 Bootstrap-vue 表

Vue 3 在一个值更改问题后再次重新渲染每一行

在 Vue 中更改 json 数据后,如何在屏幕上重新呈现表格组件?

vuetify/mdi 不显示图标

为什么将 name 与 router-link 一起使用比仅使用 to 与 path 更好?

如何从mustache内的过滤器输出html

在组件之间共享 websocket 连接

webpack vue-loader 配置

带有参数的 Vuex 映射 Getter - 缓存?

从组件的 内的组件调用方法

当前端和后端位于虚拟 docker 网络中时,如何使用 axios 寻址后端主机

Django Rest 框架、CSRF 和 Vue.js

VueJS 组件中的图像未加载

将数据传递给另一条路由上的组件

Proxy代理在 Vue 3 的控制台中是什么意思?

Vue.js webpack:如何获取目录中的文件列表?

在Vue中调用方法时的括号

Vue-i18n - 无法读取未定义的属性配置