Element UI: Setup, Forms & Tables
Element UI (by ElemeFE) is a Vue 2 component library especially popular for admin panels and dashboards -- its Vue 3 continuation is the separate but related Element Plus package. Element UI has a hard dependency on Vue 2 internals and does not work with Vue 3 at all.
Registration
// Global registration -- every component available app-wide,
// but bundles the whole library
import Vue from 'vue';
import ElementUI from 'element-ui';
import 'element-ui/lib/theme-chalk/index.css';
Vue.use(ElementUI);
// Per-component import -- more granular bundle control
import { Button, Input } from 'element-ui';
Vue.component(Button.name, Button);
Vue.component(Input.name, Input);
// el- prefix distinguishes Element UI tags from plain HTML/other components
// <el-button>, <el-input>, <el-table>, <el-dialog>Forms & Validation
<template>
<el-form :model="form" :rules="rules" ref="form">
<!-- prop links this form-item to form.email AND rules.email -->
<el-form-item prop="email" label="Email">
<el-input v-model="form.email" />
</el-form-item>
<el-form-item prop="role" label="Role">
<el-select v-model="form.role" filterable placeholder="Select role">
<el-option label="Admin" value="admin" />
<el-option label="Editor" value="editor" />
</el-select>
</el-form-item>
<el-button type="primary" @click="submit">Save</el-button>
</el-form>
</template>
<script>
export default {
data() {
return {
form: { email: '', role: '' },
rules: {
email: [
{ required: true, message: 'Email is required', trigger: 'blur' },
{ type: 'email', message: 'Invalid email', trigger: 'blur' },
],
},
};
},
methods: {
submit() {
this.$refs.form.validate((valid) => {
if (!valid) return;
// proceed with save
this.$message.success('Saved successfully');
});
},
},
};
</script>Data Tables
<el-table :data="users" @selection-change="handleSelection">
<el-table-column type="selection" width="55" />
<el-table-column prop="name" label="Name" sortable />
<el-table-column prop="email" label="Email" />
<el-table-column label="Actions">
<template slot-scope="scope">
<el-button size="mini" @click="edit(scope.row)">Edit</el-button>
</template>
</el-table-column>
</el-table>
<el-pagination
:total="totalUsers"
:page-size="20"
@current-change="handlePageChange"
/>Keep your own version of these notes — editable, searchable, and organised by your stack.
Start free