Vue3中vuejs-smart-table组件数据存在但不显示问题求助
问题排查与解决
核心问题:未正确导入并注册v-table组件
vuejs-smart-table组件不会自动全局注册,必须手动导入并注册后才能在模板中使用。你的代码里缺少组件导入和注册步骤,导致<v-table>被视为普通无效标签,无法渲染表格内容。
修复步骤
- 导入组件
在组件的<script>部分添加组件导入语句:
import { VTable } from 'vuejs-smart-table'
- 注册组件
在export default的components选项中注册VTable:
export default { name: 'users', components: { VTable // 注册后模板中才能正常使用<v-table>标签 }, data: () => ({ users }) }
- 可选:列名匹配优化
你的表头显示Name、Age,但表格内容渲染的是row.id和row.title,可根据实际数据字段调整表头文字避免混淆,比如:
<thead slot="head"> <th>ID</th> <th>Title</th> </thead>
完整修复后的代码示例
<template> <img alt="Vue logo" class="logo" src="./assets/logo.svg" width="125" height="125" /> <v-table :data="users"> <thead slot="head"> <th>ID</th> <th>Title</th> </thead> <tbody slot="body" slot-scope="{displayData}"> <tr v-for="row in displayData" :key="row.id"> <td>{{ row.id }}</td> <td>{{ row.title }}</td> </tr> </tbody> </v-table> </template> <script> import { VTable } from 'vuejs-smart-table' import users from './data/karaoke.json' export default { name: 'users', components: { VTable }, data: () => ({ users }) } </script>
内容的提问来源于stack exchange,提问作者eljiwo
相关产品推荐
相关产品推荐

