【问题标题】:template v-slot inside <v-data-table> is not working in vue 2.0.15<v-data-table> 中的模板 v-slot 在 vue 2.0.15 中不起作用
【发布时间】:2019-09-06 13:51:49
【问题描述】:

我尝试创建一个 v-data-table 包括,以便我可以使用按钮添加另一个字段,但它似乎不起作用。

代码如下: https://codepen.io/gerak/pen/yLBpqqG

问题是当我将包 https://cdnjs.cloudflare.com/ajax/libs/vuetify/1.5.14/vuetify.min.js 更改为像这样的最新版本时: https://cdnjs.cloudflare.com/ajax/libs/vuetify/2.0.15/vuetify.min.js 表忽略标签。

HTML

  <v-app id="inspire">
    <v-data-table
      :headers="headers"
      :items="desserts"
      class="elevation-1"
    >
      <template v-slot:items="props">
        <td>{{ props.item.name }}</td>
        <td >{{ props.item.calories }}</td>
        <td>{{ props.item.fat }}</td>
        <td><v-btn>Created Button</v-btn></td>
      </template>
    </v-data-table>
  </v-app>
</div>

JS

new Vue({
  el: '#app',
  data () {
    return {
      headers: [
        {
          text: 'Dessert (100g serving)',
          align: 'left',
          sortable: false,
          value: 'name'
        },
        { text: 'Calories', value: 'calories' },
        { text: 'Fat (g)', value: 'fat' },
        { text: 'Button field', value: 'buttonField' },
      ],
      desserts: [
        {
          name: 'Frozen Yogurt',
          calories: 159,
          fat: 6.0,
        },
        {
          name: 'Ice cream sandwich',
          calories: 237,
          fat: 9.0,
        },
        {
          name: 'Eclair',
          calories: 262,
          fat: 16.0,
        }
      ]
    }
  }
})

我没有收到任何错误,只有表格停止出现。会不会是版本问题?

【问题讨论】:

  • 如果我将您的 codepen 更改为使用 2.0.15,我会在控制台中看到错误您是否也更改了 css?这似乎并不重要。

标签: javascript vue.js vuetify.js


【解决方案1】:

插槽的工作方式不同,每个字段都有模板,要在表格中添加按钮,您可以这样做 (https://codepen.io/reijnemans/pen/dybJgjL?editors=1010):

<div id="app">
  <v-app id="inspire">
    <v-data-table
      :headers="headers"
      :items="desserts"
      class="elevation-1"
    >
      <template v-slot:item.action="{ item }">
        <v-btn>Created Button</v-btn>
      </template>
    </v-data-table>
  </v-app>
</div>

JS:

new Vue({
  el: '#app',
  vuetify: new Vuetify(),

  data () {
    return {
      headers: [
        {
          text: 'Dessert (100g serving)',
          align: 'left',
          sortable: false,
          value: 'name'
        },
        { text: 'Calories', value: 'calories' },
        { text: 'Fat (g)', value: 'fat' },
        { text: 'Actions', value: 'action', sortable: false }
      ],
      desserts: [
        {
          name: 'Frozen Yogurt',
          calories: 159,
          fat: 6.0,
        },
        {
          name: 'Ice cream sandwich',
          calories: 237,
          fat: 9.0,
        },
        {
          name: 'Eclair',
          calories: 262,
          fat: 16.0,
        }
      ]
    }
  }
})

【讨论】:

  • 这正是我所需要的。一个很好,简单干净的解释。谢谢!
  • @GerardoQuiros 如果此答案为您解决了问题,正常的协议是通过单击绿色复选标记来接受答案。见what to do when someone answers my question?
猜你喜欢
  • 1970-01-01
  • 2021-07-12
  • 2020-12-20
  • 2020-08-08
  • 1970-01-01
  • 2021-03-13
  • 2018-12-08
  • 2019-09-04
  • 2021-05-14
相关资源
最近更新 更多