Skip to content

Commit ed08fde

Browse files
committed
支持v-model
1 parent f34945e commit ed08fde

File tree

2 files changed

+7
-5
lines changed

2 files changed

+7
-5
lines changed

src/components/DemoSwitch.vue

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
11
<script setup lang="ts">
22
import Switch from "../lib/Switch.vue"
3+
import {ref} from "vue";
4+
let status = ref(false)
35
</script>
46
<template>
5-
<Switch />
7+
<Switch v-model="status" />
68
</template>
79

810
<style lang="scss" scoped>

src/lib/Switch.vue

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
<script setup lang="ts">
2-
import {ref} from "vue";
3-
let status = ref(false)
2+
const props = defineProps(['modelValue'])
3+
const emits = defineEmits(['update:modelValue'])
44
const onClick = ()=>{
5-
status.value = !status.value
5+
emits('update:modelValue',!props.modelValue)
66
}
77
</script>
88

99
<template>
10-
<div class="zw-switch" :class="status?'zw-switch-on':''" @click="onClick">
10+
<div class="zw-switch" :class="props.modelValue?'zw-switch-on':''" @click="onClick">
1111
<span class="node"></span>
1212
</div>
1313
</template>

0 commit comments

Comments
 (0)