ConfigProvider Component
ConfigProvider provides global configurations accessible throughout the application.
When to Use
- Internationalization
- Global component size
- Theme configuration
- Component defaults
i18n Configuration
<template>
<el-config-provider :locale="locale">
<App />
</el-config-provider>
</template>
<script setup>
import { ref } from 'vue'
import zhCn from 'element-plus/dist/locale/zh-cn.mjs'
const locale = ref(zhCn)
</script>
Global Size
<template>
<el-config-provider size="small">
<App />
</el-config-provider>
</template>
Button Configuration
<template>
<el-config-provider :button="{ autoInsertSpace: true, type: 'primary' }">
<App />
</el-config-provider>
</template>
Message Configuration
<template>
<el-config-provider :message="{ max: 3 }">
<App />
</el-config-provider>
</template>
Empty Values Configuration
<template>
<el-config-provider
:empty-values="[null, undefined]"
:value-on-clear="null"
>
<App />
</el-config-provider>
</template>
API Reference
Attributes
| Name |
Description |
Type |
Default |
| locale |
Locale object |
{ name: string, el: TranslatePair } |
English |
| size |
Global component size |
'large' | 'default' | 'small' |
'default' |
| zIndex |
Initial zIndex |
number |
— |
| namespace |
Component class prefix |
string |
'el' |
| button |
Button configuration |
{ autoInsertSpace?, type?, plain?, text?, round?, dashed? } |
— |
| link |
Link configuration |
{ type?, underline? } |
— |
| dialog |
Dialog configuration |
{ alignCenter?, draggable?, overflow?, transition? } |
— |
| message |
Message configuration |
{ max?, grouping?, duration?, showClose?, offset?, plain?, placement? } |
— |
| table |
Table configuration |
{ showOverflowTooltip?, tooltipEffect?, tooltipOptions?, tooltipFormatter? } |
— |
| empty-values |
Empty values for components |
array |
['', null, undefined] |
| value-on-clear |
Value when cleared |
string | number | boolean | Function |
undefined |
Slots
| Name |
Description |
Type |
| default |
Default content |
{ config } |
Best Practices
- Use for global i18n configuration
- Set
size for consistent component sizing
- Use
empty-values for form handling
1---
2name: "el-config-provider"
3description: "ConfigProvider component for global configuration. Invoke when user needs to configure global settings, i18n, theme, or component defaults."
4metadata:
5 source: https://skillmd.com/skills/jiaiyan/el-config-provider
6 author: jiaiyan
7 version: "1.0.0"
8---
9
10# ConfigProvider Component
11
12ConfigProvider provides global configurations accessible throughout the application.
13
14## When to Use
15
16- Internationalization
17- Global component size
18- Theme configuration
19- Component defaults
20
21## i18n Configuration
22
23```vue
24<template>
25 <el-config-provider :locale="locale">
26 <App />
27 </el-config-provider>
28</template>
29
30<script setup>
31import { ref } from 'vue'
32import zhCn from 'element-plus/dist/locale/zh-cn.mjs'
33
34const locale = ref(zhCn)
35</script>
36```
37
38## Global Size
39
40```vue
41<template>
42 <el-config-provider size="small">
43 <App />
44 </el-config-provider>
45</template>
46```
47
48## Button Configuration
49
50```vue
51<template>
52 <el-config-provider :button="{ autoInsertSpace: true, type: 'primary' }">
53 <App />
54 </el-config-provider>
55</template>
56```
57
58## Message Configuration
59
60```vue
61<template>
62 <el-config-provider :message="{ max: 3 }">
63 <App />
64 </el-config-provider>
65</template>
66```
67
68## Empty Values Configuration
69
70```vue
71<template>
72 <el-config-provider
73 :empty-values="[null, undefined]"
74 :value-on-clear="null"
75 >
76 <App />
77 </el-config-provider>
78</template>
79```
80
81## API Reference
82
83### Attributes
84
85| Name | Description | Type | Default |
86|------|-------------|------|---------|
87| locale | Locale object | `{ name: string, el: TranslatePair }` | English |
88| size | Global component size | `'large' \| 'default' \| 'small'` | `'default'` |
89| zIndex | Initial zIndex | `number` | — |
90| namespace | Component class prefix | `string` | `'el'` |
91| button | Button configuration | `{ autoInsertSpace?, type?, plain?, text?, round?, dashed? }` | — |
92| link | Link configuration | `{ type?, underline? }` | — |
93| dialog | Dialog configuration | `{ alignCenter?, draggable?, overflow?, transition? }` | — |
94| message | Message configuration | `{ max?, grouping?, duration?, showClose?, offset?, plain?, placement? }` | — |
95| table | Table configuration | `{ showOverflowTooltip?, tooltipEffect?, tooltipOptions?, tooltipFormatter? }` | — |
96| empty-values | Empty values for components | `array` | `['', null, undefined]` |
97| value-on-clear | Value when cleared | `string \| number \| boolean \| Function` | `undefined` |
98
99### Slots
100
101| Name | Description | Type |
102|------|-------------|------|
103| default | Default content | `{ config }` |
104
105## Best Practices
106
1071. Use for global i18n configuration
1082. Set `size` for consistent component sizing
1093. Use `empty-values` for form handling