Vuetify v-data-table未显示:headers和:items

huangapple go评论68阅读模式
英文:

Vuetify v-data-table not displaying :headers and :items

问题

I'm trying to build a Vue project using typescript. My v-data-table component inside Schedule.vue is not displaying. Instead all I see is the following:

我正在尝试使用TypeScript构建Vue项目。我的Schedule.vue中的v-data-table组件没有显示。我只看到如下内容:

Vuetify v-data-table未显示:headers和:items

I've tried googling everything I can but with no luck. I'm now at a point where I just re-create my project from scratch.

我已尽力搜索了所有可能的内容,但没有运气。现在我已经到了重新从头开始创建项目的地步。

Here is my Schedule.vue file:

以下是我的Schedule.vue文件:

<template>
  <div>
    <v-container>
      <v-row>
        <v-col>
          <v-data-table :headers="daoHeaders" :items="daoItems" :items-per-page="5" class="elevation-1">
            <v-toolbar-title>{{ dsTitle }}</v-toolbar-title>
          </v-data-table>
        </v-col>
      </v-row>
      <v-row>
        <v-col>
          This is below the table
        </v-col>
      </v-row>
    </v-container>
  </div>
</template>

<script lang="ts">
import { defineComponent } from 'vue';

export default defineComponent({
  data() {
    return {
      daoHeaders: [
        { title: 'Sport', key: 'sportName', align: 'start', sortable: true },
        { title: 'League', key: 'leagueName' },
        { title: 'Grade Level', key: 'gradeLevel' }
      ],
      daoItems: [
        { sportName: 'Basketball', leagueName: 'Spring Basketball League', gradeLevel: '6-12' }
      ],
      dsTitle: 'This is my Title'
    }
  },
  methods: {
  }
});
</script>

Here is my index.ts file:

以下是我的index.ts文件:

/**
 * plugins/index.ts
 *
 * Automatically included in `./src/main.ts`
 */

// Plugins
import { loadFonts } from './webfontloader';
import vuetify from './vuetify';
import router from '../router';

// Types
import type { App } from 'vue';

export function registerPlugins(app: App) {
  loadFonts()
  app
    .use(vuetify)
    .use(router)
}

Here is my main.ts file:

以下是我的main.ts文件:

/**
 * main.ts
 *
 * Bootstraps Vuetify and other plugins then mounts the App`
 */

// Components
import App from './App.vue';

// Composables
import { createApp } from 'vue';

// Plugins
import { registerPlugins } from '@/plugins';

const app = createApp(App)

registerPlugins(app)

app.mount('#app')

Here is my tsconfig.json file:

以下是我的tsconfig.json文件:

{
  "compilerOptions": {
    "baseUrl": ".",
    "target": "ESNext",
    "useDefineForClassFields": true,
    "module": "ESNext",
    "moduleResolution": "Node",
    "strict": true,
    "jsx": "preserve",
    "resolveJsonModule": true,
    "isolatedModules": true,
    "esModuleInterop": true,
    "lib": ["ESNext", "DOM"],
    "skipLibCheck": true,
    "noEmit": true,
    "paths": {
      "@/": [
        "src/*"
      ]
    }
  },
  "include": ["src/**/*.ts", "src/**/*.d.ts", "src/**/*.tsx", "src/**/*.vue", "src/main.ts"],
  "references": [{ "path": "./tsconfig.node.json" }],
  "exclude": ["node_modules"]
}

Please note that this is a direct translation of the provided content, including code snippets and comments. If you have any specific questions or need assistance with something related to this code, feel free to ask.

英文:

I'm trying to build a Vue project using typescript. My v-data-table component inside Schedule.vue is not displaying. Instead all I see is the following:

Vuetify v-data-table未显示:headers和:items

I've tried googling everything I can but with no luck. I'm now at a point where I just re-create my project from scratch.

Here is my Schedule.vue file:

<!-- begin snippet: js hide: false console: true babel: false -->

<!-- language: lang-html -->

&lt;template&gt;
  &lt;div&gt;
    &lt;v-container&gt;
      &lt;v-row&gt;
        &lt;v-col&gt;
          &lt;v-data-table :headers=&quot;daoHeaders&quot; :items=&quot;daoItems&quot; :items-per-page=&quot;5&quot; class=&quot;elevation-1&quot;&gt;
            &lt;v-toolbar-title&gt;{{ dsTitle }}&lt;/v-toolbar-title&gt;
          &lt;/v-data-table&gt;
        &lt;/v-col&gt;
      &lt;/v-row&gt;
      &lt;v-row&gt;
        &lt;v-col&gt;
          This is below the table
        &lt;/v-col&gt;
      &lt;/v-row&gt;
    &lt;/v-container&gt;
  &lt;/div&gt;
&lt;/template&gt;

&lt;script lang=&quot;ts&quot;&gt;
import { defineComponent } from &#39;vue&#39;;

export default defineComponent({
  data() {
    return {
      daoHeaders: [
        { title: &#39;Sport&#39;, key: &#39;sportName&#39;, align: &#39;start&#39;, sortable: true },
        { title: &#39;League&#39;, key: &#39;leagueName&#39; },
        { title: &#39;Grade Level&#39;, key: &#39;gradeLevel&#39; }
      ],
      daoItems: [
        { sportName: &#39;Basketball&#39;, leagueName: &#39;Spring Basketball League&#39;, gradeLevel: &#39;6-12&#39; }
      ],
      dsTitle: &#39;This is my Title&#39;
    }
  },
  methods: {
  }
});
&lt;/script&gt;

<!-- end snippet -->

Here is my index.ts file:

<!-- begin snippet: js hide: false console: true babel: false -->

<!-- language: lang-html -->

/**
 * plugins/index.ts
 *
 * Automatically included in `./src/main.ts`
 */

// Plugins
import { loadFonts } from &#39;./webfontloader&#39;
import vuetify from &#39;./vuetify&#39;
import router from &#39;../router&#39;

// Types
import type { App } from &#39;vue&#39;

export function registerPlugins (app: App) {
  loadFonts()
  app
    .use(vuetify)
    .use(router)
}

<!-- end snippet -->

<!-- begin snippet: js hide: false console: true babel: false -->

Here is my main.ts file:

<!-- language: lang-html -->

/**
 * main.ts
 *
 * Bootstraps Vuetify and other plugins then mounts the App`
 */

// Components
import App from &#39;./App.vue&#39;

// Composables
import { createApp } from &#39;vue&#39;

// Plugins
import { registerPlugins } from &#39;@/plugins&#39;

const app = createApp(App)

registerPlugins(app)

app.mount(&#39;#app&#39;)

<!-- end snippet -->

Here is my tsconfig.json file:

<!-- begin snippet: js hide: false console: true babel: false -->

<!-- language: lang-js -->

{
  &quot;compilerOptions&quot;: {
    &quot;baseUrl&quot;: &quot;.&quot;,
    &quot;target&quot;: &quot;ESNext&quot;,
    &quot;useDefineForClassFields&quot;: true,
    &quot;module&quot;: &quot;ESNext&quot;,
    &quot;moduleResolution&quot;: &quot;Node&quot;,
    &quot;strict&quot;: true,
    &quot;jsx&quot;: &quot;preserve&quot;,
    &quot;resolveJsonModule&quot;: true,
    &quot;isolatedModules&quot;: true,
    &quot;esModuleInterop&quot;: true,
    &quot;lib&quot;: [&quot;ESNext&quot;, &quot;DOM&quot;],
    &quot;skipLibCheck&quot;: true,
    &quot;noEmit&quot;: true,
    &quot;paths&quot;: {
      &quot;@/*&quot;: [
       &quot;src/*&quot;
      ]
     }
  },
  &quot;include&quot;: [&quot;src/**/*.ts&quot;, &quot;src/**/*.d.ts&quot;, &quot;src/**/*.tsx&quot;, &quot;src/**/*.vue&quot;, &quot;src/main.ts&quot;],
  &quot;references&quot;: [{ &quot;path&quot;: &quot;./tsconfig.node.json&quot; }],
  &quot;exclude&quot;: [&quot;node_modules&quot;]
}

<!-- end snippet -->

答案1

得分: 1

I think you are using the wrong naming in your v-data-table headers.

To show the data. Change your daoHeaders from title and key to text and value.

FROM

daoHeaders: [
        { title: &#39;Sport&#39;, key: &#39;sportName&#39;, align: &#39;start&#39;, sortable: true },
        { title: &#39;League&#39;, key: &#39;leagueName&#39; },
        { title: &#39;Grade Level&#39;, key: &#39;gradeLevel&#39; }
      ],

TO

daoHeaders: [
          { text: &#39;Sport&#39;, value: &#39;sportName&#39;, align: &#39;start&#39;, sortable: true },
          { text: &#39;League&#39;, value: &#39;leagueName&#39; },
          { text: &#39;Grade Level&#39;, value: &#39;gradeLevel&#39; }
        ],

Output:
Vuetify v-data-table未显示:headers和:items

英文:

I think you are using the wrong naming in your v-data-table headers.

To show the data. Change your daoHeaders from title and key to text and value.

FROM

daoHeaders: [
        { title: &#39;Sport&#39;, key: &#39;sportName&#39;, align: &#39;start&#39;, sortable: true },
        { title: &#39;League&#39;, key: &#39;leagueName&#39; },
        { title: &#39;Grade Level&#39;, key: &#39;gradeLevel&#39; }
      ],

TO

daoHeaders: [
          { text: &#39;Sport&#39;, value: &#39;sportName&#39;, align: &#39;start&#39;, sortable: true },
          { text: &#39;League&#39;, value: &#39;leagueName&#39; },
          { text: &#39;Grade Level&#39;, value: &#39;gradeLevel&#39; }
        ],

Output:
Vuetify v-data-table未显示:headers和:items

huangapple
  • 本文由 发表于 2023年4月11日 08:49:16
  • 转载请务必保留本文链接:https://go.coder-hub.com/75981692.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定