-
-
Notifications
You must be signed in to change notification settings - Fork 8.4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Mounted slot vnode.el is null #815
Comments
It looks like this other issue (closed automatically) is related: #814 |
Duplicate of vuejs/vue#9580 You can do this but I'm not sure if there's a built-in way to then render the vnode in the template, you'd have to use a render function. const slot = computed(() => slots.default())
onMounted(() => console.log(slot[0].el))
return { slot } |
This is expected, because calling slot functions technically always return fresh vnodes. The reason why The idea here is that:
|
Thanks, @yyx990803 What would be the recommended approach for adding a For the consumer perspective:
My intention here, with the wrapper component approach, was to attach event listeners to the slot's mounted DOM. Draggable would be a "renderless", behaviour-only component. Can I attach DOM event listeners by "transforming the slot vnodes at the render function level"? If not, this means I must go by "wrapping the slot with a div"? Sounds like the solution for this "draggable" idea... 🤔 I don't see a better way around it. Anyway, it will not be a "renderless" component anymore, because it will render this wrapping I wonder if I really wanted a "renderless" solution... Something very trivial, like triggering an (Well... "renderless" term may be misleading... because, after all, the component renders the slot within it...) |
You can use |
You can use the import { cloneVNode } from 'vue'
// in render fn
const slotContent = slots.default ? slots.default() : []
const transformedSlotContent = slotContent.map(vnode => cloneVNode(vnode, {
onClick: () => { /* ... */ }
})) However, I can imagine working on something like D&D can be a bit tough without free access to the DOM, so maybe wrapping slots with a wrapper element is still the easier way to do it. |
Version
3.0.0-alpha.8
Reproduction link
https://codepen.io/jbruni/pen/GRJQZpb
Steps to reproduce
console.log
at line 11 of the JavaScript code. It outputs the default slot'sel
.null
.null
. This is the bug happening. No more steps are required to reproduce.What is expected?
The output should be the mounted slot's vnode
el
- corresponding to the<div>Hi, there</div>
element.What is actually happening?
The mounted slot's vnode
el
isnull
, instead of the DOM element.The issue is related to the dynamic
<component>
used as the slot content.If you go to line 17 of the Javascript code, and change
#parent
to#parent2
, you will see the output in Console changes to<div>See you</div>
. This is an example of the expected result. In this case, the working#parent2
template contains a simplediv
as the slot content, rather than a dynamic<component>
.NOTE: I am using vue-next version 3.0.0-alpha.8, but this version is not available for selection in the Version dropdown of new-issue.vuejs.org
The text was updated successfully, but these errors were encountered: