前端组件库——TDesign Vue知识点大全(二)

简介: 教程来源 http://uklgy.cn/ TDesign提供70+高质量组件,覆盖基础交互、布局导航、数据录入与展示、用户反馈等全场景;支持基于Design Token的主题定制、深色模式及运行时动态换肤,助力企业级应用高效开发。

三、组件体系

TDesign提供了超过70个高质量组件,覆盖企业级应用开发的绝大部分场景。以下是核心组件的分类说明。

3.1 基础组件
Button按钮组件
按钮是用户交互中最基础的组件:

<template>
  <!-- 按钮类型 -->
  <t-button theme="primary">主要按钮</t-button>
  <t-button theme="default">默认按钮</t-button>
  <t-button theme="danger">危险按钮</t-button>
  <t-button theme="warning">警告按钮</t-button>
  <t-button theme="success">成功按钮</t-button>

  <!-- 按钮尺寸 -->
  <t-button size="small">小按钮</t-button>
  <t-button size="medium">中按钮</t-button>
  <t-button size="large">大按钮</t-button>

  <!-- 按钮状态 -->
  <t-button disabled>禁用按钮</t-button>
  <t-button loading>加载中</t-button>

  <!-- 图标按钮 -->
  <t-button shape="circle">
    <template #icon><t-icon name="add" /></template>
  </t-button>
</template>

Icon图标组件
TDesign内置了丰富的图标库:

<template>
  <t-icon name="check-circle" />
  <t-icon name="close-circle" />
  <t-icon name="setting" />
  <t-icon name="user" />
</template>

3.2 布局组件
Grid栅格系统
TDesign采用24列栅格系统,基于Flexbox实现:

<template>
  <t-row :gutter="16">
    <t-col :span="12">占12列</t-col>
    <t-col :span="12">占12列</t-col>
  </t-row>

  <t-row :gutter="16">
    <t-col :xs="24" :sm="12" :md="8" :lg="6">
      响应式列
    </t-col>
  </t-row>
</template>

Space间距组件
用于控制子元素之间的间距:

<template>
  <t-space direction="vertical" size="large">
    <t-button>按钮1</t-button>
    <t-button>按钮2</t-button>
  </t-space>
</template>

3.3 导航组件
Menu菜单组件
TDesign提供了侧边栏菜单和顶部菜单两种模式:

<template>
  <t-menu :value="activeMenu" :collapsed="collapsed">
    <t-menu-item value="dashboard">
      <template #icon><t-icon name="dashboard" /></template>
      仪表盘
    </t-menu-item>
    <t-submenu value="system" title="系统管理">
      <template #icon><t-icon name="setting" /></template>
      <t-menu-item value="user">用户管理</t-menu-item>
      <t-menu-item value="role">角色管理</t-menu-item>
    </t-submenu>
  </t-menu>
</template>

Breadcrumb面包屑组件
用于展示页面层级导航:

<template>
  <t-breadcrumb>
    <t-breadcrumb-item to="/">首页</t-breadcrumb-item>
    <t-breadcrumb-item to="/system">系统管理</t-breadcrumb-item>
    <t-breadcrumb-item>用户管理</t-breadcrumb-item>
  </t-breadcrumb>
</template>

Pagination分页组件

<template>
  <t-pagination
    v-model:current="currentPage"
    :total="total"
    :page-size="pageSize"
    show-jumper
    @change="handlePageChange"
  />
</template>

3.4 数据录入组件
Form表单组件
TDesign的表单组件支持完善的验证机制:

<template>
  <t-form
    ref="formRef"
    :data="formData"
    :rules="rules"
    label-width="100px"
    @submit="onSubmit"
  >
    <t-form-item label="用户名" name="username">
      <t-input v-model="formData.username" placeholder="请输入用户名" />
    </t-form-item>

    <t-form-item label="邮箱" name="email">
      <t-input v-model="formData.email" placeholder="请输入邮箱" />
    </t-form-item>

    <t-form-item>
      <t-button theme="primary" type="submit">提交</t-button>
      <t-button theme="default" @click="onReset">重置</t-button>
    </t-form-item>
  </t-form>
</template>

<script setup>
import { ref, reactive } from 'vue';
import { MessagePlugin } from 'tdesign-vue-next';

const formRef = ref();
const formData = reactive({
  username: '',
  email: '',
});

const rules = {
  username: [{ required: true, message: '请输入用户名' }],
  email: [{ required: true, message: '请输入邮箱' }, { type: 'email', message: '邮箱格式不正确' }],
};

const onSubmit = ({ validateResult, firstError }) => {
  if (validateResult === true) {
    MessagePlugin.success('提交成功');
  } else {
    MessagePlugin.warning(firstError);
  }
};
</script>

Select选择器组件

<template>
  <t-select v-model="value" placeholder="请选择" clearable filterable>
    <t-option value="option1" label="选项一" />
    <t-option value="option2" label="选项二" />
    <t-option value="option3" label="选项三" />
  </t-select>
</template>

3.5 数据展示组件
Table表格组件
表格是企业级应用中最复杂的组件之一,TDesign的Table组件功能强大:

<template>
  <t-table
    row-key="id"
    :data="data"
    :columns="columns"
    :pagination="pagination"
    :loading="loading"
    :max-height="500"
    @page-change="onPageChange"
    @sort-change="onSortChange"
  >
    <template #avatar="{ row }">
      <t-image-viewer :images="[row.avatar]">
        <template #trigger>
          <img :src="row.avatar" class="avatar" />
        </template>
      </t-image-viewer>
    </template>
    <template #status="{ row }">
      <t-tag :theme="row.status === 1 ? 'success' : 'default'">
        {
  { row.status === 1 ? '启用' : '禁用' }}
      </t-tag>
    </template>
    <template #operation="{ row }">
      <t-space>
        <t-link theme="primary" @click="handleEdit(row)">编辑</t-link>
        <t-link theme="danger" @click="handleDelete(row)">删除</t-link>
      </t-space>
    </template>
  </t-table>
</template>

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

const columns = [
  { colKey: 'id', title: 'ID', width: 80 },
  { colKey: 'name', title: '姓名', width: 120, sorter: true },
  { colKey: 'avatar', title: '头像', cell: 'avatar' },
  { colKey: 'status', title: '状态', cell: 'status' },
  { colKey: 'operation', title: '操作', cell: 'operation', width: 150, fixed: 'right' },
];

const data = ref([]);
const loading = ref(false);
const pagination = ref({
  current: 1,
  pageSize: 20,
  total: 0,
});
</script>

Card卡片组件

<template>
  <t-card title="卡片标题" :bordered="true" hover-shadow>
    <template #actions>
      <t-link theme="primary">更多</t-link>
    </template>
    <p>卡片内容区域</p>
  </t-card>
</template>

Tag标签组件

<template>
  <t-tag theme="primary">主要标签</t-tag>
  <t-tag theme="success">成功标签</t-tag>
  <t-tag theme="warning">警告标签</t-tag>
  <t-tag theme="danger">危险标签</t-tag>
  <t-tag closable @close="handleClose">可关闭标签</t-tag>
</template>

3.6 反馈组件
Dialog对话框组件

<template>
  <t-button @click="visible = true">打开对话框</t-button>
  <t-dialog
    v-model:visible="visible"
    header="对话框标题"
    :confirm-btn="confirmBtn"
    @confirm="onConfirm"
  >
    <p>对话框内容</p>
  </t-dialog>
</template>

<script setup>
import { ref } from 'vue';
import { MessagePlugin } from 'tdesign-vue-next';

const visible = ref(false);
const confirmBtn = { content: '确定', theme: 'primary' };

const onConfirm = () => {
  MessagePlugin.success('操作成功');
  visible.value = false;
};
</script>

Message全局提示

<script setup>
import { MessagePlugin } from 'tdesign-vue-next';

const showMessage = () => {
  MessagePlugin.success('操作成功');
  MessagePlugin.warning('警告信息');
  MessagePlugin.error('错误信息');
  MessagePlugin.info('提示信息');
};
</script>

Notification通知组件

<script setup>
import { NotificationPlugin } from 'tdesign-vue-next';

const showNotification = () => {
  NotificationPlugin.success({
    title: '操作成功',
    content: '您的数据已保存',
    duration: 3000,
    placement: 'top-right',
  });
};
</script>

Loading加载组件

<template>
  <t-loading :loading="loading" text="加载中...">
    <div class="content">内容区域</div>
  </t-loading>
</template>

四、主题定制

TDesign提供了完整的主题定制能力,支持运行时动态主题切换和深色模式。

4.1 Design Token体系
TDesign使用CSS自定义属性(设计令牌)作为所有可定制样式的基础。设计令牌分为多个类别:
image.png
4.2 ConfigProvider主题配置
通过ConfigProvider组件可以实现运行时主题配置:

<template>
  <t-config-provider :globalConfig="globalConfig">
    <App />
  </t-config-provider>
</template>

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

const globalConfig = ref({
  classPrefix: 't',
  // 主题配置
  theme: {
    token: {
      brandColor: '#0052d9',
      borderRadius: '6px',
    },
  },
});
</script>

4.3 深色模式
TDesign内置了对深色模式的支持,通过添加.dark类即可切换:

<template>
  <t-button @click="toggleDarkMode">切换主题</t-button>
</template>

<script setup>
const toggleDarkMode = () => {
  document.documentElement.classList.toggle('dark');
};
</script>

4.4 主题生成器
TDesign提供了主题生成工具,支持可视化的主题定制:

import { ThemeGenerator } from '@tdesign/theme-generator';

const generator = new ThemeGenerator({
  brandColor: '#0052d9',
  borderRadius: '8px',
});

// 应用生成的主题
generator.apply();

4.5 插件组件的主题支持
从版本1.18.0开始,Dialog、Message、Notification等插件式组件也支持通过ConfigProvider接收主题配置:

<template>
  <t-config-provider :globalConfig="globalConfig">
    <App />
  </t-config-provider>
</template>

<script setup>
const globalConfig = {
  theme: {
    token: {
      brandColor: '#00a870',
    },
  },
};
</script>

来源:
http://uklgy.cn/

相关文章
|
SQL XML Java
MyBatis-Plus——代码生成器(3.5.1+版本)
MyBatis-Plus——代码生成器(3.5.1+版本)
3294 0
MyBatis-Plus——代码生成器(3.5.1+版本)
Echarts实战案例代码(26):折线图组件连接空数据connectNulls的用法
Echarts实战案例代码(26):折线图组件连接空数据connectNulls的用法
1485 0
|
5月前
|
IDE 数据可视化 开发工具
2026最新Thonny(Python IDE)使用全攻略教程(附安装包+图文步骤)
Thonny是爱沙尼亚塔尔图大学开发的Python初学者专用IDE,界面极简、内置Python解释器,无需配置即可开写;其可视化调试功能可直观查看变量变化,大幅降低学习门槛。支持Win/macOS/Linux,最新版为5.x。
|
7月前
|
弹性计算 人工智能 机器人
阿里云龙虾CoPaw部署教程:基于无影云电脑一键部署,云电脑CoPawCoPaw镜像快速部署
本文详解阿里云CoPaw(龙虾)在无影云电脑个人版的一键部署全流程:含账号注册、百炼API Key获取、CoPaw镜像云电脑创建、模型配置、聊天验证及钉钉频道接入,助用户快速搭建AI智能体环境。(239字)
|
11月前
|
人工智能 安全 测试技术
让 Obsidian 会自动工作:用 n8n 打造智能知识库
通过 n8n 与 Obsidian 的 Local REST API 插件结合,实现完全自定义的自动化知识管理:自动抓取小报童文章、生成每日模板、同步邮件等,让知识库自动生长。
|
NoSQL 前端开发 PHP
Laravel 框架NOAUTH Authentication required 错误解决方案-优雅草卓伊凡
Laravel 框架NOAUTH Authentication required 错误解决方案-优雅草卓伊凡
421 2
|
安全 中间件 关系型数据库
如何选择国产化CMS来建设政务网站?
信创国产化网站建站保障信息安全,推动信息技术产业发展。PageAdminCMS支持信创,功能全面,满足新建或升级网站需求,助力单位信创国产化转型。
719 5
|
存储 安全 Java
Spring Security 6.x OAuth2登录认证源码分析
上一篇介绍了Spring Security框架中身份认证的架构设计,本篇就OAuth2客户端登录认证的实现源码做一些分析。
1583 2
Spring Security 6.x OAuth2登录认证源码分析
|
Java Maven
maven项目的pom.xml文件常用标签使用介绍
第四届人文,智慧教育与服务管理国际学术会议(HWESM 2025) 2025 4th International Conference on Humanities, Wisdom Education and Service Management
1456 8
|
编解码 定位技术
Cesium案例解析(七)——Layers在线地图服务
Cesium案例解析(七)——Layers在线地图服务
724 0

热门文章

最新文章