为啥我使用defineModel 去修改值之后 不能立即获取到最新的值 #9840
-
Beta Was this translation helpful? Give feedback.
Replies: 2 comments
-
See #9759 (comment) This behavior is expected. Within const addNum = async ()=>{
modelValue.value = modelValue.value+1
await nextTick()
alert(modelValue.value)
} |
Beta Was this translation helpful? Give feedback.
-
Thanks,i have the same question。I know it's caused by the life cycle ,but i can not find in the source code of Vue. |
Beta Was this translation helpful? Give feedback.
See #9759 (comment)
This behavior is expected. Within
defineModel
, the value ofmodelValue
is changed through event notifications, and it is modified by the parent component. When it changes, it triggers the update of the component. Since component updates are asynchronous, you must wait until the component is updated to obtain the latest value. You can usenextTick
to retrieve the most up-to-date value.