修复v-model数据未同步问题

This commit is contained in:
2024-09-20 16:54:23 +08:00
parent 21b4b9c5b5
commit e97a3df69d

View File

@@ -42,7 +42,6 @@ import { computed, ref, watch } from 'vue';
let current=ref(props.modelValue||props.defaultIndex||0)
function changeCurrent(index){
current.value=index
emit('update:modelValue',index)
}
const computedBlockStyle=computed(()=>{
const oneWidth= 100/props.list.length
@@ -52,8 +51,12 @@ import { computed, ref, watch } from 'vue';
left:left+'%'
}
})
watch(()=>current.value,()=>{
emit('change',current.value)
watch(()=>props.modelValue,(newval)=>{
current.value=newval
})
watch(()=>current.value,(newval)=>{
emit('update:modelValue',newval)
emit('change',newval)
})
</script>