TDesign Icons for Vue 2
tdesign-icons-vue provides a comprehensive set of icons specifically designed for Vue 2.x applications, serving as the official icon library within the TDesign enterprise design system. It offers flexibility in usage, allowing developers to import icons as SVG sprite components (Icon), icon font components (IconFont), or individual, tree-shakeable Vue components. The library is actively maintained as part of a mono-repo (`Tencent/tdesign-icons`), with a corresponding `tdesign-icons-vue-next` package available for Vue 3.x projects. The project observes a frequent release cadence, with regular patch and minor updates introducing new icons or optimizations, alongside occasional major version changes that may include icon renames or removals. Its key differentiators include tight integration with the TDesign ecosystem, multiple rendering options, and built-in TypeScript support.
Common errors
-
[Vue warn]: Unknown custom element: <Icon> - did you register the component correctly?
cause The `Icon` component (or any specific icon component like `CloseIcon`) was used in a Vue template without being properly imported and registered in the component's `components` option or globally with `Vue.component()`.fixEnsure `import { Icon } from 'tdesign-icons-vue';` is present and the component is registered: `components: { Icon }` or `Vue.component('TIcon', Icon);`. -
Icons not displaying, showing an empty box, or question mark characters when using <IconFont>
cause The CSS file containing the `@font-face` declaration and character mappings for the TDesign icon font is not loaded or is misconfigured.fixVerify that the icon font CSS file (e.g., from TDesign's main package or a specific icon font distribution) is imported into your main application entry point (e.g., `main.js`) or linked in your `index.html`. For example: `import 'tdesign-vue/es/style/webcomponents.css'` (path may vary). -
TypeError: Cannot read properties of undefined (reading 'name') for an icon component.
cause This typically occurs if a specific icon component (e.g., `CloseIcon`) is imported but somehow accessed incorrectly, or if `Icon` is used without a `name` prop where required, indicating the icon data is missing.fixDouble-check the import path for individual icons. If using the general `<Icon>` component, ensure the `name` prop is provided and spelled correctly, matching an existing icon.
Warnings
- breaking This package, `tdesign-icons-vue`, is specifically for Vue 2.x applications. For Vue 3.x, you must use `tdesign-icons-vue-next` instead. Using the wrong package will result in compatibility issues or runtime errors.
- breaking Icon names and availability can change between minor and major versions. Some icons may be renamed, removed, or have their definitions updated, potentially breaking existing usages, especially in major releases like 0.3.0.
- gotcha When using the `IconFont` component, you must ensure that the corresponding icon font CSS file (which defines the `@font-face` and icon classes) is properly loaded in your application. Without the CSS, icons will not render correctly.
- gotcha The `Icon` component (SVG sprite) and individual icon components can be customized with `size`, `color`, and `style` props. However, inconsistent application of these props or conflicting global styles can lead to unexpected visual results.
Install
-
npm install tdesign-icons-vue -
yarn add tdesign-icons-vue -
pnpm add tdesign-icons-vue
Imports
- Icon
const Icon = require('tdesign-icons-vue')import { Icon } from 'tdesign-icons-vue' - IconFont
import IconFont from 'tdesign-icons-vue'
import { IconFont } from 'tdesign-icons-vue' - CloseIcon
import { CloseIcon } from 'tdesign-icons-vue/es/close'import { CloseIcon } from 'tdesign-icons-vue'
Quickstart
import Vue from 'vue';
import { Icon, IconFont, CloseIcon, TimeIcon } from 'tdesign-icons-vue';
// Globally register the SVG sprite icon component
Vue.component('TIcon', Icon);
// Optionally, globally register the IconFont component
// Vue.component('TIconFont', IconFont);
new Vue({
el: '#app',
components: { CloseIcon, TimeIcon, IconFont },
template: `
<div id="app">
<h1>TDesign Icons for Vue 2</h1>
<h2>SVG Sprite Icon</h2>
<TIcon name="close" size="24px" style="color: #f00;" />
<TIcon name="time" size="32px" style="color: #00f;" />
<h2>Icon Font (requires external CSS for font-face)</h2>
<!-- Ensure the iconfont CSS is loaded globally, e.g., in your main.js or index.html -->
<!-- Example: <link rel="stylesheet" href="path/to/tdesign-iconfont.css"> -->
<IconFont name="setting" size="20px" />
<IconFont name="file" size="28px" />
<h2>Individual Icon Components</h2>
<CloseIcon size="24px" style="margin-left: 10px;" />
<TimeIcon size="24px" />
</div>
`
});