vueday02——使用NTableData

1.下载naivueui

2.按需导入,不要全局导入

注意不要导入错误组件或者写错组件名称

复制代码
import { NDataTable } from 'naive-ui'

3.定义表头和数据!!!

n-data-table标签必须要使用数据和数据 少一个都不能正确渲染!!!

复制代码
const data = ref([
    {
        key: 0,
        name: 'John Brown',
        age: 32,
        address: 'New York No. 1 Lake Park',
        tags: ['nice', 'developer']
    },
    {
        key: 1,
        name: 'Jim Green',
        age: 42,
        address: 'London No. 1 Lake Park',
        tags: ['wow']
    },
    {
        key: 2,
        name: 'Joe Black',
        age: 32,
        address: 'Sidney No. 1 Lake Park',
        tags: ['cool', 'teacher']
    }
])

const column =ref([
    {
      title: 'Name',
      key: 'name'
    },
    {
      title: 'Age',
      key: 'age'
    },
    {
      title: 'Address',
      key: 'address'
    },
    {
      title: 'Tags',
      key: 'tags',
    }],
)

4.全部代码

复制代码
<!--
 * @Author: LiuQidong 254818216@qq.com
 * @Date: 2023-10-17 02:38:53
 * @LastEditors: LiuQidong 254818216@qq.com
 * @LastEditTime: 2023-10-17 09:26:20
 * @FilePath: \newvue2\src\components\helloLQD.vue
 * @Description: 这是默认设置,请设置`customMade`, 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE
-->
<template>
    <n-data-table
    :data="data"
    :columns="column"
    :bordered="true"
  />
  <p>111</p>
</template>

<script setup="ts">
import { ref, defineComponent } from 'vue'
import { NDataTable } from 'naive-ui'

const data = ref([
    {
        key: 0,
        name: 'John Brown',
        age: 32,
        address: 'New York No. 1 Lake Park',
        tags: ['nice', 'developer']
    },
    {
        key: 1,
        name: 'Jim Green',
        age: 42,
        address: 'London No. 1 Lake Park',
        tags: ['wow']
    },
    {
        key: 2,
        name: 'Joe Black',
        age: 32,
        address: 'Sidney No. 1 Lake Park',
        tags: ['cool', 'teacher']
    }
])

const column =ref([
    {
      title: 'Name',
      key: 'name'
    },
    {
      title: 'Age',
      key: 'age'
    },
    {
      title: 'Address',
      key: 'address'
    },
    {
      title: 'Tags',
      key: 'tags',
    }],
)
</script>

5.实际效果

相关推荐
We་ct19 小时前
LeetCode 69. x 的平方根:两种解法详解
前端·javascript·算法·leetcode·typescript·平方
一直不明飞行19 小时前
C++:string,写法s.find(‘@‘) != s.end()是否有问题
开发语言·c++·算法
沐知全栈开发20 小时前
C 预处理器
开发语言
daad77720 小时前
WSL2_wifi驱动安装
开发语言·前端·javascript
超级大只老咪20 小时前
一维度前缀和解题通用模板(java)
java·开发语言·算法
无限进步_20 小时前
【C++】重载、重写和重定义的区别详解
c语言·开发语言·c++·ide·windows·git·github
许杰小刀20 小时前
Python网络请求库,从 requests 到 httpx
开发语言·python·httpx
历程里程碑20 小时前
1 . Git本地操作:版本控制 跨平台协作 仓库核心
java·开发语言·数据结构·c++·git·gitee·github
牛马11120 小时前
Flutter BoxDecoration
前端·javascript·flutter
xianluohuanxiang20 小时前
高精度气象:极端天气一来,零售最先出问题的不是客流,而是补货体系和损失控制
开发语言·人工智能·深度学习·机器学习·零售