Skip to content

Commit 7198ad4

Browse files
feature: add an API entry for mergeProps (#817)
1 parent 7eda94f commit 7198ad4

File tree

1 file changed

+23
-0
lines changed

1 file changed

+23
-0
lines changed

src/api/global-api.md

+23
Original file line numberDiff line numberDiff line change
@@ -451,3 +451,26 @@ const app = createApp({
451451
```
452452

453453
**See also**: [`$nextTick` instance method](instance-methods.html#nexttick)
454+
455+
## mergeProps
456+
457+
Takes multiple objects containing VNode props and merges them into a single object. A newly created object is returned, the objects passed as arguments are not modified.
458+
459+
Any number of objects can be passed, with properties from later arguments taking precedence. Event listeners are handled specially, as are `class` and `style`, with the values of these properties being merged rather than overwritten.
460+
461+
```js
462+
import { h, mergeProps } from 'vue'
463+
464+
export default {
465+
inheritAttrs: false,
466+
467+
render() {
468+
const props = mergeProps({
469+
// The class will be merged with any class from $attrs
470+
class: 'active'
471+
}, this.$attrs)
472+
473+
return h('div', props)
474+
}
475+
}
476+
```

0 commit comments

Comments
 (0)