Is there a way to prevent unnecessary props from being passed when using v-bind="$props"
?
#12888
-
在使用 假设有两个组件,ListItem 和 EnhancedListItem,其中 EnhancedListItem 继承了 ListItem 的所有 props,同时还增加了自己的属性(如 type 和 beforeTrack),目前我尝试了以下两种方案:
例如,在以下示例中,如何避免将 EnhancedListItem 的自有 Prop 传递给 ListItem 组件? Is there a simpler way to avoid passing unnecessary Props when using Suppose there are two components, ListItem and EnhancedListItem, where EnhancedListItem inherits all the props from ListItem, and also adds its own properties (like type and beforeTrack). So far, I have tried the following two solutions:
For example, in the following case, how can I prevent the props specific to EnhancedListItem from being passed down to the ListItem component? final: |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 2 replies
-
You listed the two methods that are available, basically. For the destructuring way, I would often rather use a helper function like lodash's You could then turn that into a more descriptive Helper: const toListItemProps (props) => pick(props, ['label', 'actions'])
``` |
Beta Was this translation helpful? Give feedback.
You listed the two methods that are available, basically. For the destructuring way, I would often rather use a helper function like lodash's
omit
orpick
.You could then turn that into a more descriptive Helper: