以下是一个简单的使用Vue3编写的表格示例:

<template>
  <div>
    <table>
      <thead>
        <tr>
          <th>姓名</th>
          <th>年龄</th>
          <th>性别</th>
        </tr>
      </thead>
      <tbody>
        <tr v-for="(person, index) in people" :key="index">
          <td>{{ person.name }}</td>
          <td>{{ person.age }}</td>
          <td>{{ person.gender }}</td>
        </tr>
      </tbody>
    </table>
  </div>
</template>

<script>
import { ref } from 'vue';

export default {
  setup() {
    const people = ref([
      { name: '张三', age: 24, gender: '男' },
      { name: '李四', age: 28, gender: '女' },
      { name: '王五', age: 32, gender: '男' },
    ]);

    return { people };
  }
}
</script>

<style>
table {
  border-collapse: collapse;
  width: 100%;
}

th, td {
  border: 1px solid black;
  padding: 8px;
  text-align: left;
}

th {
  background-color: #ddd;
}
</style>

这个示例中,我们使用了Vue3的Composition API来定义表格组件。在setup函数中,我们使用了ref函数来创建一个响应式的people数组,存储表格中的数据。在模板中,我们使用了v-for指令来遍历people数组,渲染表格中的每一行。我们还使用了基本的CSS样式来美化表格的样式。

用vue3编写表格

原文地址: http://www.cveoy.top/t/topic/YIK 著作权归作者所有。请勿转载和采集!

免费AI点我,无需注册和登录