diff --git a/packages/components/switch/src/switch.vue b/packages/components/switch/src/switch.vue
index 4fbc8bf478..0872632539 100644
--- a/packages/components/switch/src/switch.vue
+++ b/packages/components/switch/src/switch.vue
@@ -9,7 +9,7 @@
@@ -33,10 +33,10 @@
-
+
-
+
@@ -104,7 +104,12 @@ import {
CHANGE_EVENT,
INPUT_EVENT,
} from '@element-plus/utils/constants'
-import { useDisabled, useFormItem, useSize } from '@element-plus/hooks'
+import {
+ useDisabled,
+ useFormItem,
+ useNamespace,
+ useSize,
+} from '@element-plus/hooks'
import { switchProps, switchEmits } from './switch'
const COMPONENT_NAME = 'ElSwitch'
@@ -119,16 +124,16 @@ export default defineComponent({
setup(props, { emit }) {
const { formItem } = useFormItem()
const switchDisabled = useDisabled(computed(() => props.loading))
+ const ns = useNamespace('switch')
const switchSize = useSize()
const isModelValue = ref(props.modelValue !== false)
const input = ref()
const core = ref()
- const prefix = 'el-switch'
const switchKls = computed(() => [
- prefix,
- `${prefix}--${switchSize.value}`,
+ ns.b(),
+ ns.m(switchSize.value),
switchDisabled.value ? 'is-disabled' : '',
checked.value ? 'is-checked' : '',
])
@@ -239,6 +244,7 @@ export default defineComponent({
})
return {
+ ns,
input,
core,
switchDisabled,