修复v-model数据未同步问题
This commit is contained in:
@@ -42,7 +42,6 @@ import { computed, ref, watch } from 'vue';
|
|||||||
let current=ref(props.modelValue||props.defaultIndex||0)
|
let current=ref(props.modelValue||props.defaultIndex||0)
|
||||||
function changeCurrent(index){
|
function changeCurrent(index){
|
||||||
current.value=index
|
current.value=index
|
||||||
emit('update:modelValue',index)
|
|
||||||
}
|
}
|
||||||
const computedBlockStyle=computed(()=>{
|
const computedBlockStyle=computed(()=>{
|
||||||
const oneWidth= 100/props.list.length
|
const oneWidth= 100/props.list.length
|
||||||
@@ -52,8 +51,12 @@ import { computed, ref, watch } from 'vue';
|
|||||||
left:left+'%'
|
left:left+'%'
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
watch(()=>current.value,()=>{
|
watch(()=>props.modelValue,(newval)=>{
|
||||||
emit('change',current.value)
|
current.value=newval
|
||||||
|
})
|
||||||
|
watch(()=>current.value,(newval)=>{
|
||||||
|
emit('update:modelValue',newval)
|
||||||
|
emit('change',newval)
|
||||||
})
|
})
|
||||||
|
|
||||||
</script>
|
</script>
|
||||||
|
|||||||
Reference in New Issue
Block a user