【问题标题】:Vuetify table will not render when it is placed inside another componentVuetify table 放在另一个组件中时不会呈现
【发布时间】:2020-06-19 14:20:01
【问题描述】:

我在我的项目中制作了一个表格组件,因为我有多个表格,我希望它们看起来都一样。

我将表格插入我的页面,一切正常。 桌子上有一个正确打开的对话框,但在该对话框内是我的另一个表格组件,它不会呈现。 如果我更改组件的名称并有两个单独的实例,它将起作用,但这不是我想要做的。

如何让我的表格在所有组件上都工作?使用 Vue CLI。

表格组件:

<template>
  <v-data-table :headers="headers" :items="items" :no-data-text="noDataText" :dark="dark">
    <template v-slot:top>
      <v-toolbar :dark="dark" flat>
        <v-toolbar-title>{{ title }}</v-toolbar-title>
        <v-divider class="mx-4" inset vertical></v-divider>
        <v-spacer></v-spacer>
        <v-btn @click="dialog=true" color="success" class="mr-2">
          Load Default Frames
          <v-icon right>mdi-download</v-icon>
        </v-btn>
        <v-btn color="primary" class="mr-2">
          Create New Frame
          <v-icon right>mdi-image-plus</v-icon>
        </v-btn>
        <Dialog v-model="dialog" />
        <!-- <Frame v-model="dialog" :editedFrame="editedFrame" :oldIndex="oldIndex" @close="close" />
        <DefaultFrames v-model="defaultFramesDialog" :selectable="true" :items="defaultFrames" />-->
      </v-toolbar>
    </template>
  </v-data-table>
</template>

对话框组件:

<template>
  <v-dialog v-model="dialog">
    <v-card :dark="dark">
      <v-card-title>
        {{ name}}
        <v-divider class="mx-4" inset vertical></v-divider>
        <v-spacer></v-spacer>
        <v-btn icon @click="dialog = false">
          <!-- <v-icon @click="$emit('close')">mdi-close</v-icon> -->
        </v-btn>
      </v-card-title>
      <Table :is="child_component" :headers="frameHeaders" :items="defaultFrames" />
      <v-card-actions>
        <v-btn @click="log">Log</v-btn>
      </v-card-actions>
    </v-card>
  </v-dialog>
</template>

【问题讨论】:

  • 能否添加一个代码沙盒或代码笔,以便更轻松地调试问题?我有点迷失了你的对话框组件中的 从哪里获取它的属性:headers 和 :items 。

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


【解决方案1】:

Table.vue

<template>
  <v-btn @click.stop="emitOpenDialog">Open Dialog</v-btn>
</template>
<script>
  export default {
    methods: {
      emitOpenDialog() {
        // I've use vueBus for emiting
        this.$bus.emit("open-dialog")
      }
    }
  }
</script>

Dialog.vue

<template>
  <v-dialog v-model="dialog"> ... </v-dialog>
</template>
<script>
  export default {
    data: () => ({
        dialog: false
    },
    created() {
        this.$bus.on("open-dialog", this.openDialog)
    },
    beforeUnmount() {
        this.$bus.off("open-dialog")
    },
    methods: {
        openDialog() {
            this.dialog = true
        }
    }
  }

【讨论】:

    猜你喜欢
    • 2020-11-01
    • 1970-01-01
    • 2019-07-28
    • 1970-01-01
    • 1970-01-01
    • 2023-03-27
    • 1970-01-01
    • 2018-11-14
    • 1970-01-01
    相关资源
    最近更新 更多