slots el is null with interpolation
Version
3.0.0
Reproduction link
https://codepen.io/mavajee/pen/yLOQRyK
Steps to reproduce
Add interpolation inside any slot
What is expected?
has element
What is actually happening?
has null
Check dev tools console. If remove {{Math.random()}} from template, console log output slot element correctly
I don't know if this is the same issue, but this.$el
no longer works inside a watcher either:
watch: {
open() {
console.log(this.$el);
},
}
This used to work. I don't know what recent vue upgrade broke it
This does now work however:
watch: {
open() {
this.$nextTick(() => {
console.log(this.$el);
});
},
}
When you call the slot, it's not being mounted anywhere, so it's normal it doesn't have an el
. If you put it into a variable inside render
:
this.slotEl = this.$slots.default()
return h('div', this.slotEl)
then it will have the correct this.slotEl[0].el
(or similar) in mounted
@posva i call this.$slots.default()
inside mounted hook and get this thing
upd: and if call it with setTimeout ~1sec I have same result, is it normal?
yes, it's normal because you need to return the slot call inside of a render
to actually create HTML elements. I updated my comment.
Remember to use the forum or the Discord chat to ask questions!