You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
In your example, getAttrs1 returns a new object each time it runs, and v-bind gets compiled into _mergeProps($setup.getAttrs1(), { ... }). This means that whenever the parent component updates, it gets a new object after _mergeProps runs again, causing the props to change.
For the situation you mentioned, you can return a pre-declared object within the function. Refer to playground
Vue version
3.4.27
Link to minimal reproduction
https://stackblitz.com/edit/vitejs-vite-71s1ge?file=src%2FApp.vue
Steps to reproduce
提供两个组件:
index.vue
入口组件CustomTree.vue
子组件问题描述:
子组件传参如果是个函数返回的对象,在父组件回调函数中对ref/reactive声明的变量赋值,如果该变量也在模版中使用,则会导致子组件所有接收的props每次都被重置。
问题版本:
目前用了好几个版本都一样,包括最新的3.4.27,应该都存在这个问题。
问题触发前置条件:
1.给子组件传参的是个函数返回对象形式。
2.父组件的回调中是只对ref/reactive声明的响应式对象赋值才触发,普通对象不会出现问题。
3.以上两个满足后,还需要在页面中使用该属性才触发问题,只是赋值不使用不会出现问题。
使用场景:
大概如下面的伪代码,父组件中会给插槽中传值,子组件中接收父组件的这些值又在其内部进行处理,之所以这样写,也是因为属性是可以传function的,比如
element-plus
中的el-upload
的on-change/on-success
等方法也都是function的形式传参。What is expected?
在父组件的回调中正常对ref声明的变量赋值后,子组件中的参数不会被重复触发。
What is actually happening?
打开控制台上,会发现每次点击回调后,子组件的属性都会被重复触发
System Info
Any additional comments?
无
The text was updated successfully, but these errors were encountered: