Reputation: 27
vue3 has changed its slot to children of the current node. basically, this is not what I want, by using
h('div', { ... }, slots.default()) : null
it will create another div tag like this
<div>
<div>
this is content
</div>
</div>
But what I want to like this
<div>
this is content
</div>
are there some methods to achieve this?
Upvotes: 0
Views: 1601
Reputation: 138196
Use h(slots.default)
to render the default slot directly without a wrapper element (note slots.default
is not invoked for this):
import { h } from 'vue'
export default {
setup(props, { slots }) {
return () => h(slots.default, {/* props */}, [/* children */])
}
}
Or the render function could just return slots.default()
(assuming you don't need to modify any render properties or insert children):
export default {
setup(props, { slots }) {
return () => slots.default()
}
}
Upvotes: 2