
Layui Vue3
- 15 installs
- 3 repo stars
- Updated July 29, 2026
- full-statck-skills/vue-ui-skills
Guidance for the Layui Vue component library in Vue 3, covering components, layer dialogs, tables and utilities.
About
Provides guidance for building Vue 3 apps with Layui Vue components, including the Layer dialog system and data tables. A developer uses it when implementing Layui Vue UI in Vue 3.
- Covers Button, Table, DatePicker and Layer dialogs
- Includes forms, file uploads and pagination
Layui Vue3 by the numbers
- 15 all-time installs (skills.sh)
- Ranked #1,610 of 2,245 Frontend Development skills by installs in the Skillselion catalog
- Data as of Jul 30, 2026 (Skillselion catalog sync)
npx skills add https://github.com/full-statck-skills/vue-ui-skills --skill layui-vue3Add your badge
Show developers this skill is listed on Skillselion. Paste this into your README.
| Installs | 15 |
|---|---|
| repo stars | ★ 3 |
| Last updated | July 29, 2026 |
| Repository | full-statck-skills/vue-ui-skills ↗ |
What it does
Guidance for the Layui Vue component library in Vue 3, covering components, layer dialogs, tables and utilities.
Files
When to use this skill
Use this skill whenever the user wants to:
- Install and set up Layui Vue in a Vue 3 project
- Use Layui Vue components (Button, Table, DatePicker, etc.)
- Configure Layui Vue (theme, i18n, etc.)
- Use Layer component for modals and dialogs
- Implement forms with Layui Vue components
- Use data tables with sorting and pagination
- Handle file uploads
- Create dropdowns and tooltips
- Use date and time pickers
- Customize component styles
- Understand Layui Vue API and methods
- Troubleshoot Layui Vue issues
How to use this skill
1. Identify the topic from the user's request and find the corresponding example file in the mapping below
2. Load the appropriate example file from the examples/ directory
3. Follow the specific instructions in that example file for syntax, structure, and best practices
Doc mapping (one-to-one with https://www.layui-vue.com/zh-CN/)
Guide (指南):
examples/getting-started.md→ https://www.layui-vue.com/zh-CN/indexexamples/introduce.md→ https://www.layui-vue.com/zh-CN/guide/introduce
Components (组件) - examples/components/:
- See component files in
examples/components/directory - Each component file maps to https://www.layui-vue.com/zh-CN/components/[component-name]
Important Notes:
- Layui Vue is built for Vue 3
- Components use Composition API
- Supports TypeScript
- Examples include both JavaScript and TypeScript versions
- Each example file includes key concepts, code examples, and key points
4. Reference API documentation in the api/ directory when needed:
api/layer-api.md- Layer API methodsapi/component-api.md- Component API reference
5. Use templates from the templates/ directory:
templates/installation.md- Installation templatestemplates/component-usage.md- Component usage templates
1. Understanding Layui Vue
Layui Vue is a Vue 3 component library that provides a rich set of UI components, following the design philosophy of Layui.
Key Concepts:
- Vue 3 Support: Built with Vue 3 Composition API
- Rich Components: Button, Table, DatePicker, Layer, etc.
- TypeScript: Full TypeScript support
- Theme Customization: Support for theme customization
- i18n: Internationalization support
2. Installation
Using npm:
npm install @layui/layui-vueUsing yarn:
yarn add @layui/layui-vueUsing pnpm:
pnpm add @layui/layui-vue3. Basic Setup
// main.js
import { createApp } from 'vue'
import LayuiVue from '@layui/layui-vue'
import '@layui/layui-vue/lib/index.css'
import App from './App.vue'
const app = createApp(App)
app.use(LayuiVue)
app.mount('#app')4. Basic Component Usage
<template>
<lay-button type="primary">Button</lay-button>
</template>
<script setup>
import { LayButton } from '@layui/layui-vue'
</script>Examples and Templates
This skill includes detailed examples organized to match the official documentation structure. All examples are in the examples/ directory (see mapping above).
To use examples:
- Identify the topic from the user's request
- Load the appropriate example file from the mapping above
- Follow the instructions, syntax, and best practices in that file
- Adapt the code examples to your specific use case
To use templates:
- Reference templates in
templates/directory for common scaffolding - Adapt templates to your specific needs and coding style
API Reference
Detailed API documentation is available in the api/ directory, organized to match the official Layui Vue API documentation structure:
Layer API (api/layer-api.md)
layer.open()- Open modal/dialoglayer.close()- Close layerlayer.msg()- Show messagelayer.confirm()- Show confirmation dialoglayer.load()- Show loadinglayer.drawer()- Show drawer
Component API (api/component-api.md)
- Component props and events
- Component methods
- Component slots
To use API reference: 1. Identify the API you need help with 2. Load the corresponding API file from the api/ directory 3. Find the API signature, parameters, return type, and examples 4. Reference the linked example files for detailed usage patterns 5. All API files include links to relevant example files in the examples/ directory
Best Practices
1. Use TypeScript: Take advantage of TypeScript support 2. Import on demand: Import only needed components 3. Follow component API: Use props and events correctly 4. Customize theme: Use theme variables for customization 5. Handle events: Properly handle component events 6. Use Layer API: Use Layer API for modals and dialogs
Resources
- Official Documentation: https://www.layui-vue.com/zh-CN/index
- Getting Started: https://www.layui-vue.com/zh-CN/guide/introduce
- Components: https://www.layui-vue.com/zh-CN/components
- GitHub Repository: https://github.com/layui-vue/layui-vue
Keywords
Layui Vue, layui-vue, Vue 3, component library, UI components, Button, Table, DatePicker, Layer, Dropdown, Tooltip, Form, Input, Select, Checkbox, Radio, Switch, Upload, 组件库, 按钮, 表格, 日期选择器, 弹层, 下拉菜单, 提示, 表单, 输入框, 选择器, 复选框, 单选框, 开关, 上传
能力边界
✅ 适用场景
- 当你需要使用此技能对应的技术栈时
- 当项目需要遵循最佳实践时
- 当需要快速上手或深入理解核心概念时
⚠️ 需要注意
- 复杂业务逻辑需要结合具体场景调整
- 性能优化需要根据实际数据量评估
❌ 不适用场景
- 不相关的技术栈或框架
- 需要完全自定义的特殊场景
常见陷阱 (Gotchas)
1. 版本兼容性:注意框架版本与依赖库的兼容性,不同版本 API 可能有差异 2. 配置文件格式:配置文件格式错误是最常见的问题,建议使用编辑器的语法检查 3. 环境变量:确保所有必要的环境变量已正确设置,敏感信息不要硬编码 4. 依赖冲突:多版本共存时注意依赖冲突,使用 lock 文件锁定版本 5. 性能陷阱:大数据量场景下注意性能优化,避免 N+1 查询等常见问题
使用流程
Step 1: 环境准备
确保开发环境已安装必要的依赖和工具。
Step 2: 配置初始化
根据项目需求进行基础配置。
Step 3: 核心功能使用
按照示例代码实现核心功能。
Step 4: 测试验证
运行测试确保功能正常。
Step 5: 部署上线
完成开发后进行部署和监控。
Component API
API Reference
Layui Vue component props, events, and methods.
Common Props
Most components support:
size- Component size (lg, md, sm, xs)disabled- Disabled stateloading- Loading state
Common Events
Most components emit:
@click- Click event@change- Change event@input- Input event
Button Component
Props:
type- Button type (primary, normal, warm, danger)size- Button sizedisabled- Disabled stateloading- Loading stateicon- Icon name
Events:
@click- Click event
Table Component
Props:
columns- Column configurationdataSource- Table datapagination- Pagination configsortable- Enable sortingcheckbox- Enable row selection
Events:
@change- Pagination/sort change@select- Row selection change
DatePicker Component
Props:
v-model- Selected datetype- Picker type (date, datetime, year, month, daterange)format- Date formatshortcuts- Date shortcuts
Events:
@change- Date change event
Input Component
Props:
v-model- Input valueplaceholder- Placeholder textdisabled- Disabled statereadonly- Readonly stateprefixIcon- Prefix iconsuffixIcon- Suffix icon
Events:
@input- Input event@change- Change event@blur- Blur event@focus- Focus event
See also: examples/components/ for detailed component examples
Layer API
API Reference
Layer API methods for modals, dialogs, and messages.
layer.open(options)
Type: Function
Open a modal/dialog layer.
Parameters:
options- Configuration object
Options:
title- Layer titlecontent- Layer contentarea- Layer size [width, height]type- Layer type (0: info, 1: page, 2: iframe)shade- Show shade (default: true)shadeClose- Close on shade click (default: true)offset- Layer offset [x, y]anim- Animation type
Returns: number - Layer index
Example:
import { layer } from '@layui/layui-vue'
const index = layer.open({
title: 'Title',
content: 'Content',
area: ['500px', '300px']
})layer.close(index)
Type: Function
Close a layer by index.
Parameters:
index- Layer index
Example:
layer.close(index)layer.msg(content, options?)
Type: Function
Show a message.
Parameters:
content- Message contentoptions- Options (time, icon, etc.)
Example:
layer.msg('Hello World')
layer.msg('Success', { icon: 1 })layer.confirm(content, options?)
Type: Function
Show a confirmation dialog.
Parameters:
content- Confirmation messageoptions- Options with yes/no callbacks
Example:
layer.confirm('Are you sure?', {
yes: (index) => {
console.log('Confirmed')
layer.close(index)
}
})layer.load(content?, options?)
Type: Function
Show loading layer.
Returns: number - Layer index
Example:
const index = layer.load()
setTimeout(() => {
layer.close(index)
}, 2000)layer.drawer(options)
Type: Function
Open a drawer.
Options:
content- Drawer contentdirection- Drawer direction (left, right, top, bottom)
Example:
layer.drawer({
content: 'Drawer Content',
direction: 'right'
})See also: examples/components/layer.md
Button Component
官方文档: https://www.layui-vue.com/zh-CN/components/button
Instructions
This example demonstrates the Button component in Layui Vue.
Key Concepts
- Button types
- Button sizes
- Button states
- Button events
Example: Basic Button
<template>
<lay-button>Default</lay-button>
<lay-button type="primary">Primary</lay-button>
<lay-button type="normal">Normal</lay-button>
<lay-button type="warm">Warm</lay-button>
<lay-button type="danger">Danger</lay-button>
</template>
<script setup>
import { LayButton } from '@layui/layui-vue'
</script>Example: Button Sizes
<template>
<lay-button size="lg">Large</lay-button>
<lay-button size="md">Medium</lay-button>
<lay-button size="sm">Small</lay-button>
<lay-button size="xs">Extra Small</lay-button>
</template>Example: Button States
<template>
<lay-button disabled>Disabled</lay-button>
<lay-button loading>Loading</lay-button>
</template>Example: Button with Icon
<template>
<lay-button icon="layui-icon-search">Search</lay-button>
<lay-button icon="layui-icon-add-circle">Add</lay-button>
</template>Example: Button Events
<template>
<lay-button @click="handleClick">Click Me</lay-button>
</template>
<script setup>
import { LayButton } from '@layui/layui-vue'
const handleClick = () => {
console.log('Button clicked')
}
</script>Key Points
- Multiple types: primary, normal, warm, danger
- Multiple sizes: lg, md, sm, xs
- Support for disabled and loading states
- Icon support
- Click event handling
Checkbox Component
官方文档: https://www.layui-vue.com/zh-CN/components/checkbox
Instructions
This example demonstrates the Checkbox component in Layui Vue.
Key Concepts
- Single checkbox
- Checkbox group
- Checkbox states
- Checkbox events
Example: Basic Checkbox
<template>
<lay-checkbox v-model="checked">Checkbox</lay-checkbox>
</template>
<script setup>
import { ref } from 'vue'
import { LayCheckbox } from '@layui/layui-vue'
const checked = ref(false)
</script>Example: Checkbox Group
<template>
<lay-checkbox-group v-model="checkedList">
<lay-checkbox value="1">Option 1</lay-checkbox>
<lay-checkbox value="2">Option 2</lay-checkbox>
<lay-checkbox value="3">Option 3</lay-checkbox>
</lay-checkbox-group>
</template>
<script setup>
import { ref } from 'vue'
import { LayCheckbox, LayCheckboxGroup } from '@layui/layui-vue'
const checkedList = ref([])
</script>Example: Checkbox States
<template>
<lay-checkbox v-model="checked" disabled>Disabled</lay-checkbox>
<lay-checkbox v-model="checked" :indeterminate="indeterminate">Indeterminate</lay-checkbox>
</template>
<script setup>
import { ref } from 'vue'
import { LayCheckbox } from '@layui/layui-vue'
const checked = ref(false)
const indeterminate = ref(true)
</script>Example: Checkbox Events
<template>
<lay-checkbox
v-model="checked"
@change="handleChange"
>Checkbox</lay-checkbox>
</template>
<script setup>
import { ref } from 'vue'
import { LayCheckbox } from '@layui/layui-vue'
const checked = ref(false)
const handleChange = (val) => {
console.log('Checked:', val)
}
</script>Key Points
- Use v-model for two-way binding
- Use lay-checkbox-group for multiple checkboxes
- Support disabled and indeterminate states
- Handle change events
- Configure checkbox values
DatePicker Component
官方文档: https://www.layui-vue.com/zh-CN/components/date-picker
Instructions
This example demonstrates the DatePicker component in Layui Vue.
Key Concepts
- Date selection
- Date range
- Date formats
- Date picker types
Example: Basic DatePicker
<template>
<lay-date-picker v-model="date"></lay-date-picker>
</template>
<script setup>
import { ref } from 'vue'
import { LayDatePicker } from '@layui/layui-vue'
const date = ref('')
</script>Example: Date Range
<template>
<lay-date-picker
v-model="dateRange"
type="daterange"
></lay-date-picker>
</template>
<script setup>
import { ref } from 'vue'
import { LayDatePicker } from '@layui/layui-vue'
const dateRange = ref([])
</script>Example: Date Format
<template>
<lay-date-picker
v-model="date"
format="YYYY-MM-DD"
></lay-date-picker>
</template>Example: Date Picker Types
<template>
<lay-date-picker type="date"></lay-date-picker>
<lay-date-picker type="datetime"></lay-date-picker>
<lay-date-picker type="year"></lay-date-picker>
<lay-date-picker type="month"></lay-date-picker>
</template>Example: Date Picker with Options
<template>
<lay-date-picker
v-model="date"
:shortcuts="shortcuts"
></lay-date-picker>
</template>
<script setup>
import { ref } from 'vue'
import { LayDatePicker } from '@layui/layui-vue'
const date = ref('')
const shortcuts = [
{ text: 'Today', value: new Date() },
{ text: 'Yesterday', value: () => {
const d = new Date()
d.setDate(d.getDate() - 1)
return d
}}
]
</script>Key Points
- Use v-model for two-way binding
- Support date range selection
- Configure date format
- Multiple picker types
- Shortcuts support
Dropdown Component
官方文档: https://www.layui-vue.com/zh-CN/components/dropdown
Instructions
This example demonstrates the Dropdown component in Layui Vue.
Key Concepts
- Dropdown menu
- Dropdown items
- Dropdown trigger
- Dropdown events
Example: Basic Dropdown
<template>
<lay-dropdown>
<lay-button>Dropdown</lay-button>
<template #content>
<lay-dropdown-item>Option 1</lay-dropdown-item>
<lay-dropdown-item>Option 2</lay-dropdown-item>
<lay-dropdown-item>Option 3</lay-dropdown-item>
</template>
</lay-dropdown>
</template>
<script setup>
import { LayDropdown, LayDropdownItem, LayButton } from '@layui/layui-vue'
</script>Example: Dropdown with Click Event
<template>
<lay-dropdown>
<lay-button>Actions</lay-button>
<template #content>
<lay-dropdown-item @click="handleClick1">Edit</lay-dropdown-item>
<lay-dropdown-item @click="handleClick2">Delete</lay-dropdown-item>
</template>
</lay-dropdown>
</template>
<script setup>
import { LayDropdown, LayDropdownItem, LayButton } from '@layui/layui-vue'
const handleClick1 = () => {
console.log('Edit clicked')
}
const handleClick2 = () => {
console.log('Delete clicked')
}
</script>Example: Dropdown Trigger
<template>
<lay-dropdown trigger="hover">
<lay-button>Hover Me</lay-button>
<template #content>
<lay-dropdown-item>Option 1</lay-dropdown-item>
<lay-dropdown-item>Option 2</lay-dropdown-item>
</template>
</lay-dropdown>
</template>Key Points
- Use lay-dropdown for container
- Use lay-dropdown-item for menu items
- Support click and hover triggers
- Handle item click events
- Customize dropdown content
Form Component
官方文档: https://www.layui-vue.com/zh-CN/components/form
Instructions
This example demonstrates the Form component in Layui Vue.
Key Concepts
- Form structure
- Form validation
- Form submission
- Form fields
Example: Basic Form
<template>
<lay-form :model="form" :rules="rules">
<lay-form-item label="Name" prop="name">
<lay-input v-model="form.name"></lay-input>
</lay-form-item>
<lay-form-item label="Email" prop="email">
<lay-input v-model="form.email"></lay-input>
</lay-form-item>
<lay-form-item>
<lay-button type="primary" @click="submit">Submit</lay-button>
</lay-form-item>
</lay-form>
</template>
<script setup>
import { ref } from 'vue'
import { LayForm, LayFormItem, LayInput, LayButton } from '@layui/layui-vue'
const form = ref({
name: '',
email: ''
})
const rules = {
name: [{ required: true, message: 'Name is required' }],
email: [{ required: true, message: 'Email is required' }]
}
const submit = () => {
// Handle form submission
}
</script>Example: Form Validation
<template>
<lay-form ref="formRef" :model="form" :rules="rules">
<lay-form-item label="Name" prop="name">
<lay-input v-model="form.name"></lay-input>
</lay-form-item>
<lay-form-item>
<lay-button type="primary" @click="validate">Validate</lay-button>
</lay-form-item>
</lay-form>
</template>
<script setup>
import { ref } from 'vue'
import { LayForm, LayFormItem, LayInput, LayButton } from '@layui/layui-vue'
const formRef = ref()
const form = ref({ name: '' })
const rules = {
name: [{ required: true, message: 'Name is required' }]
}
const validate = async () => {
await formRef.value.validate()
}
</script>Key Points
- Use lay-form for form container
- Use lay-form-item for form fields
- Configure validation rules
- Use ref to access form methods
- Handle form submission
Input Component
官方文档: https://www.layui-vue.com/zh-CN/components/input
Instructions
This example demonstrates the Input component in Layui Vue.
Key Concepts
- Input types
- Input sizes
- Input states
- Input events
Example: Basic Input
<template>
<lay-input v-model="value" placeholder="Enter text"></lay-input>
</template>
<script setup>
import { ref } from 'vue'
import { LayInput } from '@layui/layui-vue'
const value = ref('')
</script>Example: Input Sizes
<template>
<lay-input size="lg" v-model="value1"></lay-input>
<lay-input size="md" v-model="value2"></lay-input>
<lay-input size="sm" v-model="value3"></lay-input>
</template>Example: Input States
<template>
<lay-input disabled v-model="value"></lay-input>
<lay-input readonly v-model="value"></lay-input>
</template>Example: Input with Icon
<template>
<lay-input
v-model="value"
prefix-icon="layui-icon-search"
></lay-input>
<lay-input
v-model="value"
suffix-icon="layui-icon-close"
></lay-input>
</template>Example: Input Events
<template>
<lay-input
v-model="value"
@input="handleInput"
@change="handleChange"
@blur="handleBlur"
@focus="handleFocus"
></lay-input>
</template>
<script setup>
import { ref } from 'vue'
import { LayInput } from '@layui/layui-vue'
const value = ref('')
const handleInput = (val) => {
console.log('Input:', val)
}
const handleChange = (val) => {
console.log('Change:', val)
}
</script>Key Points
- Use v-model for two-way binding
- Multiple sizes: lg, md, sm
- Support disabled and readonly
- Icon support (prefix/suffix)
- Multiple events: input, change, blur, focus
Layer Component
官方文档: https://www.layui-vue.com/zh-CN/components/layer
Instructions
This example demonstrates the Layer component in Layui Vue.
Key Concepts
- Layer component usage
- Layer API methods
- Modal dialogs
- Drawer
- Message and confirm
Example: Layer Component
<template>
<lay-layer v-model="visible" title="Title">
<p>Content</p>
</lay-layer>
<lay-button @click="visible = true">Open</lay-button>
</template>
<script setup>
import { ref } from 'vue'
import { LayLayer, LayButton } from '@layui/layui-vue'
const visible = ref(false)
</script>Example: Layer API - Open
<template>
<lay-button @click="openLayer">Open Layer</lay-button>
</template>
<script setup>
import { LayButton } from '@layui/layui-vue'
import { layer } from '@layui/layui-vue'
const openLayer = () => {
layer.open({
title: 'Title',
content: 'Content',
area: ['500px', '300px']
})
}
</script>Example: Layer API - Message
<template>
<lay-button @click="showMessage">Show Message</lay-button>
</template>
<script setup>
import { LayButton } from '@layui/layui-vue'
import { layer } from '@layui/layui-vue'
const showMessage = () => {
layer.msg('Hello World')
}
</script>Example: Layer API - Confirm
<template>
<lay-button @click="showConfirm">Confirm</lay-button>
</template>
<script setup>
import { LayButton } from '@layui/layui-vue'
import { layer } from '@layui/layui-vue'
const showConfirm = () => {
layer.confirm('Are you sure?', {
yes: (index) => {
console.log('Confirmed')
layer.close(index)
}
})
}
</script>Example: Layer API - Loading
<template>
<lay-button @click="showLoading">Loading</lay-button>
</template>
<script setup>
import { LayButton } from '@layui/layui-vue'
import { layer } from '@layui/layui-vue'
const showLoading = () => {
const index = layer.load()
setTimeout(() => {
layer.close(index)
}, 2000)
}
</script>Example: Drawer
<template>
<lay-button @click="openDrawer">Open Drawer</lay-button>
</template>
<script setup>
import { LayButton } from '@layui/layui-vue'
import { layer } from '@layui/layui-vue'
const openDrawer = () => {
layer.drawer({
content: 'Drawer Content',
direction: 'right'
})
}
</script>Key Points
- Use component or API methods
- layer.open() for modals
- layer.msg() for messages
- layer.confirm() for confirmations
- layer.load() for loading
- layer.drawer() for drawers
Radio Component
官方文档: https://www.layui-vue.com/zh-CN/components/radio
Instructions
This example demonstrates the Radio component in Layui Vue.
Key Concepts
- Single radio
- Radio group
- Radio states
- Radio events
Example: Basic Radio
<template>
<lay-radio v-model="value" value="1">Option 1</lay-radio>
<lay-radio v-model="value" value="2">Option 2</lay-radio>
</template>
<script setup>
import { ref } from 'vue'
import { LayRadio } from '@layui/layui-vue'
const value = ref('1')
</script>Example: Radio Group
<template>
<lay-radio-group v-model="value">
<lay-radio value="1">Option 1</lay-radio>
<lay-radio value="2">Option 2</lay-radio>
<lay-radio value="3">Option 3</lay-radio>
</lay-radio-group>
</template>
<script setup>
import { ref } from 'vue'
import { LayRadio, LayRadioGroup } from '@layui/layui-vue'
const value = ref('1')
</script>Example: Radio States
<template>
<lay-radio v-model="value" value="1" disabled>Disabled</lay-radio>
</template>Example: Radio Events
<template>
<lay-radio-group v-model="value" @change="handleChange">
<lay-radio value="1">Option 1</lay-radio>
<lay-radio value="2">Option 2</lay-radio>
</lay-radio-group>
</template>
<script setup>
import { ref } from 'vue'
import { LayRadio, LayRadioGroup } from '@layui/layui-vue'
const value = ref('1')
const handleChange = (val) => {
console.log('Selected:', val)
}
</script>Key Points
- Use v-model for two-way binding
- Use lay-radio-group for radio groups
- Set value for each radio
- Support disabled state
- Handle change events
Segmented Component
官方文档: https://www.layui-vue.com/zh-CN/components/segmented
Instructions
This example demonstrates the Segmented component in Layui Vue.
Key Concepts
- Segmented options
- Segmented selection
- Segmented events
- Segmented styling
Example: Basic Segmented
<template>
<lay-segmented v-model="value" :options="options"></lay-segmented>
</template>
<script setup>
import { ref } from 'vue'
import { LaySegmented } from '@layui/layui-vue'
const value = ref('1')
const options = [
{ label: 'Option 1', value: '1' },
{ label: 'Option 2', value: '2' },
{ label: 'Option 3', value: '3' }
]
</script>Example: Segmented with Icons
<template>
<lay-segmented v-model="value" :options="options"></lay-segmented>
</template>
<script setup>
import { ref } from 'vue'
import { LaySegmented } from '@layui/layui-vue'
const value = ref('1')
const options = [
{ label: 'List', value: '1', icon: 'layui-icon-list' },
{ label: 'Grid', value: '2', icon: 'layui-icon-grid' }
]
</script>Example: Segmented Events
<template>
<lay-segmented
v-model="value"
:options="options"
@change="handleChange"
></lay-segmented>
</template>
<script setup>
import { ref } from 'vue'
import { LaySegmented } from '@layui/layui-vue'
const value = ref('1')
const options = [
{ label: 'Option 1', value: '1' },
{ label: 'Option 2', value: '2' }
]
const handleChange = (val) => {
console.log('Selected:', val)
}
</script>Key Points
- Use v-model for two-way binding
- Configure options array
- Support icons in options
- Handle change events
- Customize appearance
Select Component
官方文档: https://www.layui-vue.com/zh-CN/components/select
Instructions
This example demonstrates the Select component in Layui Vue.
Key Concepts
- Select options
- Multiple selection
- Searchable select
- Select events
Example: Basic Select
<template>
<lay-select v-model="value" :options="options"></lay-select>
</template>
<script setup>
import { ref } from 'vue'
import { LaySelect } from '@layui/layui-vue'
const value = ref('')
const options = [
{ label: 'Option 1', value: '1' },
{ label: 'Option 2', value: '2' },
{ label: 'Option 3', value: '3' }
]
</script>Example: Multiple Selection
<template>
<lay-select
v-model="value"
:options="options"
multiple
></lay-select>
</template>
<script setup>
import { ref } from 'vue'
import { LaySelect } from '@layui/layui-vue'
const value = ref([])
const options = [
{ label: 'Option 1', value: '1' },
{ label: 'Option 2', value: '2' }
]
</script>Example: Searchable Select
<template>
<lay-select
v-model="value"
:options="options"
searchable
></lay-select>
</template>Example: Select with Placeholder
<template>
<lay-select
v-model="value"
:options="options"
placeholder="Please select"
></lay-select>
</template>Key Points
- Use v-model for two-way binding
- Configure options array
- Enable multiple selection
- Enable searchable mode
- Support placeholder
Switch Component
官方文档: https://www.layui-vue.com/zh-CN/components/switch
Instructions
This example demonstrates the Switch component in Layui Vue.
Key Concepts
- Switch state
- Switch sizes
- Switch colors
- Switch events
Example: Basic Switch
<template>
<lay-switch v-model="checked"></lay-switch>
</template>
<script setup>
import { ref } from 'vue'
import { LaySwitch } from '@layui/layui-vue'
const checked = ref(false)
</script>Example: Switch with Label
<template>
<lay-switch v-model="checked">Enable Feature</lay-switch>
</template>Example: Switch Sizes
<template>
<lay-switch v-model="checked1" size="lg"></lay-switch>
<lay-switch v-model="checked2" size="md"></lay-switch>
<lay-switch v-model="checked3" size="sm"></lay-switch>
</template>Example: Switch States
<template>
<lay-switch v-model="checked" disabled>Disabled</lay-switch>
<lay-switch v-model="checked" loading>Loading</lay-switch>
</template>Example: Switch Events
<template>
<lay-switch
v-model="checked"
@change="handleChange"
></lay-switch>
</template>
<script setup>
import { ref } from 'vue'
import { LaySwitch } from '@layui/layui-vue'
const checked = ref(false)
const handleChange = (val) => {
console.log('Switch:', val)
}
</script>Key Points
- Use v-model for two-way binding
- Support label text
- Multiple sizes: lg, md, sm
- Support disabled and loading states
- Handle change events
Table Component
官方文档: https://www.layui-vue.com/zh-CN/components/table
Instructions
This example demonstrates the Table component in Layui Vue.
Key Concepts
- Table data
- Columns configuration
- Sorting
- Pagination
- Selection
Example: Basic Table
<template>
<lay-table :columns="columns" :data-source="dataSource"></lay-table>
</template>
<script setup>
import { ref } from 'vue'
import { LayTable } from '@layui/layui-vue'
const columns = [
{ title: 'ID', key: 'id' },
{ title: 'Name', key: 'name' },
{ title: 'Email', key: 'email' }
]
const dataSource = ref([
{ id: 1, name: 'John', email: 'john@example.com' },
{ id: 2, name: 'Jane', email: 'jane@example.com' }
])
</script>Example: Table with Sorting
<template>
<lay-table :columns="columns" :data-source="dataSource" :sortable="true"></lay-table>
</template>
<script setup>
import { ref } from 'vue'
import { LayTable } from '@layui/layui-vue'
const columns = [
{ title: 'ID', key: 'id', sort: true },
{ title: 'Name', key: 'name', sort: true }
]
const dataSource = ref([
{ id: 1, name: 'John' },
{ id: 2, name: 'Jane' }
])
</script>Example: Table with Pagination
<template>
<lay-table
:columns="columns"
:data-source="dataSource"
:pagination="pagination"
@change="handleChange"
></lay-table>
</template>
<script setup>
import { ref } from 'vue'
import { LayTable } from '@layui/layui-vue'
const columns = [
{ title: 'ID', key: 'id' },
{ title: 'Name', key: 'name' }
]
const dataSource = ref([...])
const pagination = ref({
current: 1,
pageSize: 10,
total: 100
})
const handleChange = (page, pageSize) => {
// Handle pagination change
}
</script>Example: Table with Selection
<template>
<lay-table
:columns="columns"
:data-source="dataSource"
:checkbox="true"
v-model:selectedKeys="selectedKeys"
></lay-table>
</template>
<script setup>
import { ref } from 'vue'
import { LayTable } from '@layui/layui-vue'
const selectedKeys = ref([])
</script>Key Points
- Configure columns and data source
- Enable sorting with sort: true
- Configure pagination
- Support row selection
- Handle table events
TagInput Component
官方文档: https://www.layui-vue.com/zh-CN/components/tag-input
Instructions
This example demonstrates the TagInput component in Layui Vue.
Key Concepts
- Tag input
- Tag management
- Tag validation
- Tag events
Example: Basic TagInput
<template>
<lay-tag-input v-model="tags"></lay-tag-input>
</template>
<script setup>
import { ref } from 'vue'
import { LayTagInput } from '@layui/layui-vue'
const tags = ref([])
</script>Example: TagInput with Validation
<template>
<lay-tag-input
v-model="tags"
:max-length="5"
@change="handleChange"
></lay-tag-input>
</template>
<script setup>
import { ref } from 'vue'
import { LayTagInput } from '@layui/layui-vue'
const tags = ref([])
const handleChange = (tags) => {
console.log('Tags:', tags)
}
</script>Example: TagInput with Placeholder
<template>
<lay-tag-input
v-model="tags"
placeholder="Enter tags"
></lay-tag-input>
</template>Key Points
- Use v-model for two-way binding
- Tags stored as array
- Support max length validation
- Handle change events
- Customize placeholder
TimeSelect Component
官方文档: https://www.layui-vue.com/zh-CN/components/time-select
Instructions
This example demonstrates the TimeSelect component in Layui Vue.
Key Concepts
- Time selection
- Time format
- Time range
- Time picker options
Example: Basic TimeSelect
<template>
<lay-time-select v-model="time"></lay-time-select>
</template>
<script setup>
import { ref } from 'vue'
import { LayTimeSelect } from '@layui/layui-vue'
const time = ref('')
</script>Example: TimeSelect with Format
<template>
<lay-time-select
v-model="time"
format="HH:mm:ss"
></lay-time-select>
</template>Example: TimeSelect with Steps
<template>
<lay-time-select
v-model="time"
:step="30"
></lay-time-select>
</template>Example: TimeSelect Range
<template>
<lay-time-select
v-model="timeRange"
range
></lay-time-select>
</template>
<script setup>
import { ref } from 'vue'
import { LayTimeSelect } from '@layui/layui-vue'
const timeRange = ref([])
</script>Key Points
- Use v-model for two-way binding
- Configure time format
- Set time step interval
- Support time range selection
- Customize picker options
Tooltip Component
官方文档: https://www.layui-vue.com/zh-CN/components/tooltip
Instructions
This example demonstrates the Tooltip component in Layui Vue.
Key Concepts
- Tooltip placement
- Tooltip content
- Tooltip trigger
- Tooltip styling
Example: Basic Tooltip
<template>
<lay-tooltip content="This is a tooltip">
<lay-button>Hover Me</lay-button>
</lay-tooltip>
</template>
<script setup>
import { LayTooltip, LayButton } from '@layui/layui-vue'
</script>Example: Tooltip Placement
<template>
<lay-tooltip content="Tooltip" placement="top">
<lay-button>Top</lay-button>
</lay-tooltip>
<lay-tooltip content="Tooltip" placement="bottom">
<lay-button>Bottom</lay-button>
</lay-tooltip>
<lay-tooltip content="Tooltip" placement="left">
<lay-button>Left</lay-button>
</lay-tooltip>
<lay-tooltip content="Tooltip" placement="right">
<lay-button>Right</lay-button>
</lay-tooltip>
</template>Example: Tooltip Trigger
<template>
<lay-tooltip content="Tooltip" trigger="click">
<lay-button>Click Me</lay-button>
</lay-tooltip>
</template>Example: Tooltip with HTML Content
<template>
<lay-tooltip>
<template #content>
<div>
<strong>Title</strong>
<p>Description</p>
</div>
</template>
<lay-button>Hover</lay-button>
</lay-tooltip>
</template>Key Points
- Wrap content with lay-tooltip
- Configure placement (top, bottom, left, right)
- Set trigger (hover, click, focus)
- Support HTML content via slot
- Customize tooltip appearance
Upload Component
官方文档: https://www.layui-vue.com/zh-CN/components/upload
Instructions
This example demonstrates the Upload component in Layui Vue.
Key Concepts
- File upload
- Upload progress
- File validation
- Upload events
Example: Basic Upload
<template>
<lay-upload
:action="uploadUrl"
@success="handleSuccess"
></lay-upload>
</template>
<script setup>
import { LayUpload } from '@layui/layui-vue'
const uploadUrl = '/api/upload'
const handleSuccess = (response) => {
console.log('Upload success:', response)
}
</script>Example: Upload with Validation
<template>
<lay-upload
:action="uploadUrl"
:accept="'image/*'"
:max-size="5 * 1024 * 1024"
@error="handleError"
></lay-upload>
</template>
<script setup>
import { LayUpload } from '@layui/layui-vue'
const handleError = (error) => {
console.log('Upload error:', error)
}
</script>Example: Multiple Files
<template>
<lay-upload
:action="uploadUrl"
multiple
:max-count="5"
></lay-upload>
</template>Example: Upload with Preview
<template>
<lay-upload
:action="uploadUrl"
:file-list="fileList"
@change="handleChange"
></lay-upload>
</template>
<script setup>
import { ref } from 'vue'
import { LayUpload } from '@layui/layui-vue'
const fileList = ref([])
const handleChange = (files) => {
fileList.value = files
}
</script>Key Points
- Configure upload URL
- Set file validation rules
- Support multiple files
- Handle upload events
- Preview uploaded files
Getting Started
官方文档: https://www.layui-vue.com/zh-CN/index
Instructions
This example demonstrates how to get started with Layui Vue.
Key Concepts
- Installation
- Basic setup
- Import components
- Global registration
Example: Installation
# Using npm
npm install @layui/layui-vue
# Using yarn
yarn add @layui/layui-vue
# Using pnpm
pnpm add @layui/layui-vueExample: Global Registration
// main.js
import { createApp } from 'vue'
import LayuiVue from '@layui/layui-vue'
import '@layui/layui-vue/lib/index.css'
import App from './App.vue'
const app = createApp(App)
app.use(LayuiVue)
app.mount('#app')Example: Import on Demand
// main.js
import { createApp } from 'vue'
import { LayButton, LayTable } from '@layui/layui-vue'
import '@layui/layui-vue/lib/index.css'
import App from './App.vue'
const app = createApp(App)
app.component('LayButton', LayButton)
app.component('LayTable', LayTable)
app.mount('#app')Example: Component Usage
<template>
<lay-button type="primary">Primary Button</lay-button>
<lay-button type="normal">Normal Button</lay-button>
</template>
<script setup>
import { LayButton } from '@layui/layui-vue'
</script>Example: TypeScript Setup
// main.ts
import { createApp } from 'vue'
import LayuiVue from '@layui/layui-vue'
import '@layui/layui-vue/lib/index.css'
import App from './App.vue'
const app = createApp(App)
app.use(LayuiVue)
app.mount('#app')Key Points
- Install @layui/layui-vue package
- Import CSS file
- Register globally or import on demand
- Use components in templates
- Supports TypeScript
Introduction
官方文档: https://www.layui-vue.com/zh-CN/guide/introduce
Instructions
This example provides an introduction to Layui Vue.
Key Concepts
- What is Layui Vue
- Features
- Design philosophy
- Component overview
Example: What is Layui Vue
Layui Vue is a Vue 3 component library that provides a rich set of UI components, following the design philosophy of Layui.
Key Features:
- Built with Vue 3 Composition API
- Full TypeScript support
- Rich component set
- Theme customization
- Internationalization support
Example: Component Categories
Form Components:
- Button, Input, Select, Checkbox, Radio, Switch
- DatePicker, TimeSelect, TagInput
- Upload, Form
Data Display:
- Table, Tag, Badge, Card
- List, Tree
Feedback:
- Layer (Modal/Dialog), Tooltip, Message
- Loading, Progress
Navigation:
- Dropdown, Menu, Breadcrumb
- Tabs, Segmented
Example: Design Philosophy
- Simplicity: Easy to use and understand
- Consistency: Consistent design language
- Flexibility: Customizable and extensible
- Performance: Optimized for performance
Key Points
- Vue 3 component library
- Rich component ecosystem
- TypeScript support
- Theme customization
- Good documentation
Apache License
Version 2.0, January 2004
http://www.apache.org/licenses/
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
1. Definitions.
"License" shall mean the terms and conditions for use, reproduction,
and distribution as defined by Sections 1 through 9 of this document.
"Licensor" shall mean the copyright owner or entity authorized by
the copyright owner that is granting the License.
"Legal Entity" shall mean the union of the acting entity and all
other entities that control, are controlled by, or are under common
control with that entity. For the purposes of this definition,
"control" means (i) the power, direct or indirect, to cause the
direction or management of such entity, whether by contract or
otherwise, or (ii) ownership of fifty percent (50%) or more of the
outstanding shares, or (iii) beneficial ownership of such entity.
"You" (or "Your") shall mean an individual or Legal Entity
exercising permissions granted by this License.
"Source" form shall mean the preferred form for making modifications,
including but not limited to software source code, documentation
source, and configuration files.
"Object" form shall mean any form resulting from mechanical
transformation or translation of a Source form, including but
not limited to compiled object code, generated documentation,
and conversions to other media types.
"Work" shall mean the work of authorship, whether in Source or
Object form, made available under the License, as indicated by a
copyright notice that is included in or attached to the work
(an example is provided in the Appendix below).
"Derivative Works" shall mean any work, whether in Source or Object
form, that is based on (or derived from) the Work and for which the
editorial revisions, annotations, elaborations, or other modifications
represent, as a whole, an original work of authorship. For the purposes
of this License, Derivative Works shall not include works that remain
separable from, or merely link (or bind by name) to the interfaces of,
the Work and Derivative Works thereof.
"Contribution" shall mean any work of authorship, including
the original version of the Work and any modifications or additions
to that Work or Derivative Works thereof, that is intentionally
submitted to Licensor for inclusion in the Work by the copyright owner
or by an individual or Legal Entity authorized to submit on behalf of
the copyright owner. For the purposes of this definition, "submitted"
means any form of electronic, verbal, or written communication sent
to the Licensor or its representatives, including but not limited to
communication on electronic mailing lists, source code control systems,
and issue tracking systems that are managed by, or on behalf of, the
Licensor for the purpose of discussing and improving the Work, but
excluding communication that is conspicuously marked or otherwise
designated in writing by the copyright owner as "Not a Contribution."
"Contributor" shall mean Licensor and any individual or Legal Entity
on behalf of whom a Contribution has been received by Licensor and
subsequently incorporated within the Work.
2. Grant of Copyright License. Subject to the terms and conditions of
this License, each Contributor hereby grants to You a perpetual,
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
copyright license to reproduce, prepare Derivative Works of,
publicly display, publicly perform, sublicense, and distribute the
Work and such Derivative Works in Source or Object form.
3. Grant of Patent License. Subject to the terms and conditions of
this License, each Contributor hereby grants to You a perpetual,
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
(except as stated in this section) patent license to make, have made,
use, offer to sell, sell, import, and otherwise transfer the Work,
where such license applies only to those patent claims licensable
by such Contributor that are necessarily infringed by their
Contribution(s) alone or by combination of their Contribution(s)
with the Work to which such Contribution(s) was submitted. If You
institute patent litigation against any entity (including a
cross-claim or counterclaim in a lawsuit) alleging that the Work
or a Contribution incorporated within the Work constitutes direct
or contributory patent infringement, then any patent licenses
granted to You under this License for that Work shall terminate
as of the date such litigation is filed.
4. Redistribution. You may reproduce and distribute copies of the
Work or Derivative Works thereof in any medium, with or without
modifications, and in Source or Object form, provided that You
meet the following conditions:
(a) You must give any other recipients of the Work or
Derivative Works a copy of this License; and
(b) You must cause any modified files to carry prominent notices
stating that You changed the files; and
(c) You must retain, in the Source form of any Derivative Works
that You distribute, all copyright, patent, trademark, and
attribution notices from the Source form of the Work,
excluding those notices that do not pertain to any part of
the Derivative Works; and
(d) If the Work includes a "NOTICE" text file as part of its
distribution, then any Derivative Works that You distribute must
include a readable copy of the attribution notices contained
within such NOTICE file, excluding those notices that do not
pertain to any part of the Derivative Works, in at least one
of the following places: within a NOTICE text file distributed
as part of the Derivative Works; within the Source form or
documentation, if provided along with the Derivative Works; or,
within a display generated by the Derivative Works, if and
wherever such third-party notices normally appear. The contents
of the NOTICE file are for informational purposes only and
do not modify the License. You may add Your own attribution
notices within Derivative Works that You distribute, alongside
or as an addendum to the NOTICE text from the Work, provided
that such additional attribution notices cannot be construed
as modifying the License.
You may add Your own copyright statement to Your modifications and
may provide additional or different license terms and conditions
for use, reproduction, or distribution of Your modifications, or
for any such Derivative Works as a whole, provided Your use,
reproduction, and distribution of the Work otherwise complies with
the conditions stated in this License.
5. Submission of Contributions. Unless You explicitly state otherwise,
any Contribution intentionally submitted for inclusion in the Work
by You to the Licensor shall be under the terms and conditions of
this License, without any additional terms or conditions.
Notwithstanding the above, nothing herein shall supersede or modify
the terms of any separate license agreement you may have executed
with Licensor regarding such Contributions.
6. Trademarks. This License does not grant permission to use the trade
names, trademarks, service marks, or product names of the Licensor,
except as required for reasonable and customary use in describing the
origin of the Work and reproducing the content of the NOTICE file.
7. Disclaimer of Warranty. Unless required by applicable law or
agreed to in writing, Licensor provides the Work (and each
Contributor provides its Contributions) on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
implied, including, without limitation, any warranties or conditions
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
PARTICULAR PURPOSE. You are solely responsible for determining the
appropriateness of using or redistributing the Work and assume any
risks associated with Your exercise of permissions under this License.
8. Limitation of Liability. In no event and under no legal theory,
whether in tort (including negligence), contract, or otherwise,
unless required by applicable law (such as deliberate and grossly
negligent acts) or agreed to in writing, shall any Contributor be
liable to You for damages, including any direct, indirect, special,
incidental, or consequential damages of any character arising as a
result of this License or out of the use or inability to use the
Work (including but not limited to damages for loss of goodwill,
work stoppage, computer failure or malfunction, or any and all
other commercial damages or losses), even if such Contributor
has been advised of the possibility of such damages.
9. Accepting Warranty or Additional Liability. While redistributing
the Work or Derivative Works thereof, You may choose to offer,
and charge a fee for, acceptance of support, warranty, indemnity,
or other liability obligations and/or rights consistent with this
License. However, in accepting such obligations, You may act only
on Your own behalf and on Your sole responsibility, not on behalf
of any other Contributor, and only if You agree to indemnify,
defend, and hold each Contributor harmless for any liability
incurred by, or claims asserted against, such Contributor by reason
of your accepting any such warranty or additional liability.
END OF TERMS AND CONDITIONS
APPENDIX: How to apply the Apache License to your work.
To apply the Apache License to your work, attach the following
boilerplate notice, with the fields enclosed by brackets "[]"
replaced with your own identifying information. (Don't include
the brackets!) The text should be enclosed in the appropriate
comment syntax for the file format. We also recommend that a
file or class name and description of purpose be included on the
same "printed page" as the copyright notice for easier
identification within third-party archives.
Copyright [yyyy] [name of copyright owner]
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
Component Usage Templates
Button Usage
<template>
<lay-button type="primary" @click="handleClick">
Click Me
</lay-button>
</template>
<script setup>
import { LayButton } from '@layui/layui-vue'
const handleClick = () => {
console.log('Clicked')
}
</script>Table Usage
<template>
<lay-table
:columns="columns"
:data-source="dataSource"
:pagination="pagination"
></lay-table>
</template>
<script setup>
import { ref } from 'vue'
import { LayTable } from '@layui/layui-vue'
const columns = [
{ title: 'ID', key: 'id' },
{ title: 'Name', key: 'name' }
]
const dataSource = ref([
{ id: 1, name: 'John' },
{ id: 2, name: 'Jane' }
])
const pagination = ref({
current: 1,
pageSize: 10,
total: 100
})
</script>Form Usage
<template>
<lay-form :model="form" :rules="rules">
<lay-form-item label="Name" prop="name">
<lay-input v-model="form.name"></lay-input>
</lay-form-item>
<lay-form-item>
<lay-button type="primary" @click="submit">Submit</lay-button>
</lay-form-item>
</lay-form>
</template>
<script setup>
import { ref } from 'vue'
import { LayForm, LayFormItem, LayInput, LayButton } from '@layui/layui-vue'
const form = ref({
name: ''
})
const rules = {
name: [{ required: true, message: 'Name is required' }]
}
const submit = () => {
// Handle submission
}
</script>Layer Usage
<template>
<lay-button @click="openLayer">Open</lay-button>
</template>
<script setup>
import { LayButton } from '@layui/layui-vue'
import { layer } from '@layui/layui-vue'
const openLayer = () => {
layer.open({
title: 'Title',
content: 'Content'
})
}
</script>Installation Templates
Global Installation
// main.js
import { createApp } from 'vue'
import LayuiVue from '@layui/layui-vue'
import '@layui/layui-vue/lib/index.css'
import App from './App.vue'
const app = createApp(App)
app.use(LayuiVue)
app.mount('#app')Import on Demand
// main.js
import { createApp } from 'vue'
import { LayButton, LayTable, LayInput } from '@layui/layui-vue'
import '@layui/layui-vue/lib/index.css'
import App from './App.vue'
const app = createApp(App)
app.component('LayButton', LayButton)
app.component('LayTable', LayTable)
app.component('LayInput', LayInput)
app.mount('#app')TypeScript Setup
// main.ts
import { createApp } from 'vue'
import LayuiVue from '@layui/layui-vue'
import '@layui/layui-vue/lib/index.css'
import App from './App.vue'
const app = createApp(App)
app.use(LayuiVue)
app.mount('#app')Component Usage
<template>
<lay-button type="primary">Button</lay-button>
</template>
<script setup>
import { LayButton } from '@layui/layui-vue'
</script>