Element Plus
Element Plus is a comprehensive UI component library for Vue 3, built entirely with the Composition API and TypeScript. It offers a rich set of customizable components designed to streamline development of web applications. The library is currently at version 2.13.7 and maintains a frequent release cadence, often releasing multiple patch versions per month to address bugs and introduce minor features, with occasional minor versions for larger feature sets. Key differentiators include its strong TypeScript support, native Vue 3 reactivity, and an extensive ecosystem of tools and documentation, making it a robust alternative to older Vue 2 UI libraries like Element UI.
Common errors
-
[Vue warn]: Failed to resolve component: ElButton
cause Element Plus components are not properly registered with the Vue application or the component using them.fixEnsure you have called `app.use(ElementPlus);` in your main application entry file (e.g., `main.ts` or `main.js`). If using individual components without global registration, ensure they are imported and registered locally in your Vue component's `<script setup>` or `components` option. -
TypeError: Cannot read properties of undefined (reading 'use') at main.js:X:Y
cause This typically occurs when trying to use CommonJS `require()` syntax (e.g., `const ElementPlus = require('element-plus');`) in a modern Vue 3 project which expects ES Module imports.fixReplace `const ElementPlus = require('element-plus');` with `import ElementPlus from 'element-plus';` in your entry file. -
Element Plus components appear unstyled or with only basic browser styling.
cause The main stylesheet for Element Plus has not been imported into your project.fixAdd `import 'element-plus/dist/index.css';` to your main application entry file (e.g., `main.ts` or `main.js`).
Warnings
- breaking Migrating from Element UI (Vue 2) to Element Plus (Vue 3) involves significant breaking changes due to the underlying Vue version upgrade and API redesign. A dedicated migration tool and detailed breaking change list are available.
- gotcha Element Plus requires Node.js version 20 or higher for development environments. Older Node.js versions may lead to build errors or unexpected behavior.
- gotcha Starting with version 2.13.0, Element Plus officially supports and recommends Vue 3.5. While it might work with older Vue 3 versions (>=3.3.0), using Vue 3.5 ensures full compatibility and access to the latest features and optimizations.
Install
-
npm install element-plus -
yarn add element-plus -
pnpm add element-plus
Imports
- ElementPlus (global install)
const ElementPlus = require('element-plus');import ElementPlus from 'element-plus';
- ElButton (specific component)
import ElButton from 'element-plus/lib/ElButton';
import { ElButton } from 'element-plus'; - Element Plus CSS
import 'element-plus/lib/theme-chalk/index.css';
import 'element-plus/dist/index.css';
- ButtonInstance (type)
import type { ButtonInstance } from 'element-plus';
Quickstart
import { createApp, ref } from 'vue';
import ElementPlus from 'element-plus';
import 'element-plus/dist/index.css';
import { ElMessage } from 'element-plus'; // For programmatic use
const App = {
setup() {
const inputValue = ref('');
const message = ref('Hello Element Plus!');
const showFeedback = () => {
ElMessage.success('Button clicked!');
};
return {
inputValue,
message,
showFeedback
};
},
template: `
<div style="text-align: center; margin-top: 50px;">
<h1>{{ message }}</h1>
<ElButton type="primary" @click="showFeedback">Click Me</ElButton>
<ElInput
v-model="inputValue"
placeholder="Type something..."
style="width: 300px; margin: 20px;"
/>
<p v-if="inputValue">You typed: {{ inputValue }}</p>
<ElLink href="https://element-plus.org/" target="_blank">Documentation</ElLink>
</div>
`
};
const app = createApp(App);
app.use(ElementPlus);
app.mount('#app');