Skip to content

Commit 83ad136

Browse files
committed
使用v-model
1 parent 3cd2fbe commit 83ad136

File tree

2 files changed

+4
-2
lines changed

2 files changed

+4
-2
lines changed

src/components/SwitchDemo.vue

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<template>
22
<div>
3-
<Switch :value="y" @input="y = $event" />
3+
<Switch v-model:value="y" />
44
</div>
55
</template>
66
<script lang="ts">

src/lib/Switch.vue

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,11 @@ export default {
77
props:{
88
value:Boolean
99
},
10+
// props和context 传值方式
1011
setup(props,context){
1112
const toggle = ()=>{
12-
context.emit('input', !props.value)
13+
// 事件:vue3的v-model改动,之前是input
14+
context.emit('update:value', !props.value)
1315
}
1416
return { toggle }
1517
}

0 commit comments

Comments
 (0)