javascript - v-数据表 : bind a custom property to "items" slot

标签 javascript vue.js vuejs2 vuetify.js

我需要创建一个表,其中每一行代表一个项目。在第一列中,我将使用 v-autocomplete 组件从对象列表中选择项目。由于 v-autocomplete 将被插入到 v-data-table 的项目模板中,我在将计算属性绑定(bind)到 v-autocomplete 的“v-bind:items”时遇到了问题。计算属性在同一个文件中,但找不到。

我尝试将计算属性绑定(bind)到模板,但没有结果。

<template>
  <v-data-table
    :headers="headers"
    :items="desserts"
    class="elevation-1"
  >
    <template slot="items" slot-scope="props">
      <td>
        <v-autocomplete
          :items="saleables"
          :item-text="i => i.name"
          :item-value="i => i.id"
          hide-details
        ></v-autocomplete>
      </td>
      <td class="text-xs-right">{{ props.item.calories }}</td>
      <td class="text-xs-right">{{ props.item.fat }}</td>
      <td class="text-xs-right">{{ props.item.carbs }}</td>
      <td class="text-xs-right">{{ props.item.protein }}</td>
    </template>
  </v-data-table>
<template>


[...]
computed: {
  saleables: function () {
    return this.$store.getters['saleables/items']
  }
}
[...]

最佳答案

你应该用 <v-app> 包装你的模板标记如下:

  <template>
     <v-app>
      <v-data-table ...
        ...
      </v-data-table>
    </v-app>
 <template>

official docs 中所述:

In order for your application to work properly, you must wrap it in a v-app component. This component is required for determining grid breakpoints for the layout. This can exist anywhere inside the body, but must be the parent of ALL Vuetify components. v-content needs to be a direct descendant of v-app.

关于javascript - v-数据表 : bind a custom property to "items" slot,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54504877/

相关文章:

javascript:通过增加 objectKeys 值来更新对象

javascript - Material ui 列表项中图标按钮的工具提示未按预期工作

javascript - Vuejs 3 webpack : Problem with vue-template-compiler

vue.js - VueJS : How to navigate to a different route from global JS function

javascript - 在 Vue JS 中的 v-for 循环期间分配局部变量

javascript - 我如何模拟人为的ajax搜索?

javascript - 正则表达式仅搜索/替换文本,不在 HTML 属性中

vue.js - 在 VueJS 中为 Get、Post、Patch 配置全局 header 的最佳方法

javascript - Datalist - 如何在单击选项上启动功能?

vue.js - 未调用 Vue prop 验证