【问题标题】:How to access slot object property to pass into component for a given data table row in Vuetify?如何访问插槽对象属性以传递给 Vuetify 中给定数据表行的组件?
【发布时间】:2020-08-22 13:35:46
【问题描述】:

我有一个像这样的 vue 数据属性:

data() {
   orders: [],
   order: {
      order_id: null
      length: null,
      width: null,
   }
}

我有像这样的 vuetify 数据表:

<v-data-table
  v-if="orders.length > 0"
  :headers="headers"
  :items="orders"
  multi-sort
  :search="search"
  class="elevation-1"
 >
<template v-slot:[`item.length`]="{ item }">
 <span>{{item.length | transform}}</span>
</template>
<template v-slot:[`item.weight`]="{ item }">
 <span>{{item.weight | transform}}</span>
</template>
<template  v-slot:[`item.actions`]>
 <v-icon small @click="cancelOverlay = true" color="red">mdi-cancel</v-icon>
 <v-overlay v-if="cancelOverlay">
  <v-card light color="#f6f9fc" max-width="1000px">
   <v-card-title primary-title>
    <div>
     <span class="display-1 mb-0 black--text">Are you sure you want to cancel your order?</span>
    </div>
    <v-spacer></v-spacer>
    <v-btn icon dark color="black" @click="cancelOverlay = false">
     <v-icon>mdi-close</v-icon>
    </v-btn>
   </v-card-title>
   <v-container>
    <CancelOrderComponent :orderId="item.order_id" />
   </v-container>
  </v-card>
 </v-overlay>
</template>
</v-data-table>

在我的orders 数组中,每个元素都有一个名为order_id 的属性,我没有在我的数据表中显示它。

当我尝试将item.order_id 传递给我的CancelOrderComponent 时,我收到以下错误:

Cannot read property 'order_id' of undefined

如何访问order_id 以获取数据表中的给定行,以便正确地将其传递到CancelOrderComponent

【问题讨论】:

    标签: javascript vue.js vuejs2 vue-component vuetify.js


    【解决方案1】:

    您缺少在&lt;template v-slot:['item.actions']&gt; 中添加插槽道具,所以您应该这样做:

    <template  v-slot:[`item.actions`]="{item}">
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2014-11-16
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-12-01
      • 2020-03-12
      • 1970-01-01
      相关资源
      最近更新 更多