Subscribe on changes!

slots el is null with interpolation

avatar
Sep 21st 2020

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

avatar
9mm
Sep 22nd 2020

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);
      });
    },
  }
avatar
Sep 22nd 2020

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

avatar
Sep 22nd 2020

@posva i call this.$slots.default() inside mounted hook and get this thing Screenshot 2020-09-22 at 10 15 28

upd: and if call it with setTimeout ~1sec I have same result, is it normal?

avatar
Sep 22nd 2020

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!