Appearance
Switch 开关
状态切换
正常:
禁用:
这是 Switch
基础例子
vue
<script setup lang="ts">
import { ref } from 'vue'
const test = ref(false)
const test2 = ref(false)
</script>
<template>
<div class="switch-demo">
<div>
正常:<NpSwitch v-model="test" />
</div>
<div>
禁用:<NpSwitch v-model="test2" disabled />
</div>
</div>
</template>
<style scoped>
.switch-demo {
margin: 20px;
display: flex;
align-items: center;
gap: 20px;
}
</style>
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
这是 Switch
不同尺寸的例子
vue
<script setup lang="ts">
import { ref } from 'vue'
const test = ref(false)
</script>
<template>
<div class="switch-demo">
<NpSwitch v-model="test" size="large" />
<NpSwitch v-model="test" />
<NpSwitch v-model="test" size="small" />
</div>
</template>
<style scoped>
.switch-demo {
margin: 20px;
display: flex;
align-items: center;
gap: 20px;
}
</style>
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
Value: false
OFF
这是 Switch
文字描述的例子
vue
<script setup lang="ts">
import { ref } from 'vue'
const test = ref(false)
</script>
<template>
<div class="switch-demo">
<h2>Value: {{ test }}</h2>
</div>
<div class="switch-demo">
<NpSwitch v-model="test" green active-value="Enable" inactive-value="Disable" />
<NpSwitch v-model="test" green active-text="ON" inactive-text="OFF" />
</div>
</template>
<style scoped>
.switch-demo {
margin: 20px;
display: flex;
gap: 20px;
}
</style>
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23