defineExpose
Vue version
3.2.43
Link to minimal reproduction
Steps to reproduce
- click f12 to look console
- click hour / day input to switch mode parent component ref while updated, child component will receive parent component ref child component expose a function which read props
- child component exposed function read props not updated correctly
What is expected?
child component read props correctly, which means props is equal to passed props by parent component
What is actually happening?
props is not equal to parent component data
System Info
No response
Any additional comments?
No response
- function handleUpdate(type) {
+ async function handleUpdate(type) {
if(type ===timeMetrics.value) {return}
timeMetrics.value = type
console.log(timeMetrics.value)
selectedColumns.value= [{title: 'demo'}, ...makeTableColumns(type)]
console.log('parent', selectedColumns.value)
+ await nextTick()
compRef.value.init()
}
You need to wait for the Comp
to finish updating.
- function handleUpdate(type) { + async function handleUpdate(type) { if(type ===timeMetrics.value) {return} timeMetrics.value = type console.log(timeMetrics.value) selectedColumns.value= [{title: 'demo'}, ...makeTableColumns(type)] console.log('parent', selectedColumns.value) + await nextTick() compRef.value.init() }
You need to wait for the
Comp
to finish updating.
thx for reply, i main if there is another way to refresh child component will be more effectual, real code will do something in child component onMount function to make something only once, when i use key in child component is also cause error
in this demo , just switch input radio frequently can use component key to accomplish my point?
@RosApr I'm sorry! I can't follow your point.
In Vue, when the component's state changes, the component is updated asynchronously. So if you want to get the latest props, you must wait for the component to finish updating.