Vue.js 是一种流行的 JavaScript 框架,用于构建用户界面。在 Vue 中,我们可以使用自定义组件来创建各种可重用的 UI 元素。本文将介绍如何自定义一个表格组件,并提供相应的源代码。
首先,我们需要创建一个 Vue 组件来表示表格。在这个组件中,我们将定义表格的结构和行为。以下是一个简单的示例:
<template>
<table>
<thead>
<tr>
<th v-for="column in columns" :key="column.field">{
{ column.label }}</th>
</tr>
</thead>
<tbody>
<tr v-for="item in data" :key="item.id">
<td v-for="column in columns" :key="column.field">{
{ item[column.field] }}</td>
</tr>
</tbody>
</table>
</template>
<script>
export default {
props: {
columns: {
type: Array,
required: true
},
data: {
t