TDesign Vue 2.x UI Library
tdesign-vue is the official Vue 2.x component library from Tencent's TDesign specification. It provides a comprehensive set of high-quality UI components designed for desktop applications, featuring consistent APIs and UI across various TDesign framework libraries. The library supports dark mode, customizable themes, and tree-shaking for optimized bundle sizes. Currently at version 1.14.5, it observes a frequent release cadence with regular bug fixes and feature additions. Key differentiators include its backing by Tencent, enterprise-grade component suite, and robust TypeScript support, making it suitable for large-scale business applications targeting Vue 2 environments. It is distinct from `tdesign-vue-next`, which targets Vue 3.x.
Common errors
-
[Vue warn]: Unknown custom element: <t-button> - did you register the component correctly?
cause TDesign components were not properly registered with the Vue application, or styles were not imported, leading to rendering issues.fixEnsure you have `import Vue from 'vue'; import TDesign from 'tdesign-vue'; import 'tdesign-vue/es/style/index.css'; Vue.use(TDesign);` in your main application entry file (e.g., `main.js`). If using individual imports, make sure each component is imported and registered (either globally or in the component's `components` option). -
Module not found: Error: Can't resolve 'tdesign-vue/es/style/index.css'
cause The main CSS file for TDesign Vue is missing or the import path is incorrect. This can happen if the package is not installed correctly or the build tool cannot locate the stylesheet.fixVerify that `tdesign-vue` is correctly installed (`npm install tdesign-vue`) and ensure the import path `import 'tdesign-vue/es/style/index.css';` is correct in your main application entry point. Also, check your build configuration (e.g., Webpack, Vite) for CSS loading. -
Property 'alert' does not exist on type 'Vue'.
cause This TypeScript error occurs when a TDesign plugin method, like `$alert`, is accessed on the Vue instance (`this`) but the TypeScript compiler does not know about it. This is usually due to missing or incorrect global type declarations.fixEnsure that TDesign's global type declarations are included in your TypeScript configuration. For `tdesign-vue`, you might need to add `node_modules/tdesign-vue/global.d.ts` to your `tsconfig.json`'s `include` array or create a custom `d.ts` file to augment the `Vue` interface if auto-detection fails.
Warnings
- breaking The `tdesign-icons-vue` dependency, which provides icons for `tdesign-vue`, underwent significant changes in version 0.4.x (released with `tdesign-vue` 1.14.0). Several icons, specifically `video-camera-3`, `video-camera-3-filled`, and `list`, were removed.
- breaking The `ColorPicker` component in `tdesign-vue` 1.12.0 introduced changes to its gradient mode and removed the `HSB` format. Businesses relying on the `ColorPicker`'s gradient functionality or the `HSB` color format should be aware of these breaking changes.
- deprecated The `Alert` component's `close` API was deprecated in favor of `closeBtn` in version 1.13.0. The `close` prop will be removed in a future major version.
- gotcha This library (`tdesign-vue`) is specifically built for Vue 2.x. It is not directly compatible with Vue 3.x applications. Attempting to use it in a Vue 3 project will lead to runtime errors or unexpected behavior, as `tdesign-vue-next` is the dedicated Vue 3 version.
Install
-
npm install tdesign-vue -
yarn add tdesign-vue -
pnpm add tdesign-vue
Imports
- TDesign
const TDesign = require('tdesign-vue');import Vue from 'vue'; import TDesign from 'tdesign-vue'; import 'tdesign-vue/es/style/index.css'; Vue.use(TDesign);
- Button
import Button from 'tdesign-vue/lib/button';
import { Button } from 'tdesign-vue'; - TButtonProps
import type { ButtonProps as TButtonProps } from 'tdesign-vue';
Quickstart
import Vue from 'vue';
import TDesign from 'tdesign-vue';
import 'tdesign-vue/es/style/index.css';
// Import specific component styles if needed, or rely on global styles
// import 'tdesign-vue/es/button/style/index.css';
Vue.use(TDesign);
new Vue({
el: '#app',
template: `
<div id="app">
<t-space direction="vertical">
<h1>TDesign Vue Quickstart</h1>
<t-button theme="primary" @click="handleClick">Hello TDesign!</t-button>
<t-date-picker />
</t-space>
</div>
`,
methods: {
handleClick() {
this.$alert('Button Clicked!', 'Info');
}
}
});