Open
Description
Version
2.6.11
Reproduction link
https://jsfiddle.net/y9kmcbg6/
Steps to reproduce
- JSFiddle will render both elements.
- After 3s, it will toggle off
- After 3s, it will toggle on
- To see it happen again, rerun the jsfiddle
What is expected?
At step 3, the bottom slot content should re-appear when ToggleComponent toggles back
What is actually happening?
The bottom slot never re-appears
Seems to be related to the v-if
on line 21. I'm doing this b/c it's useful to have an optional slot, but I don't want an extra div to appear when the slot isn't used (for layout reasons). I'm fairly new to vue, so I don't know if there's a different recommended way to do this.
Not documented in the example, but if ParentComponent updates, the slot content will re-appear
example code included here for perusal:
const ToggleComponent = {
data() {
return {
toggleEl: true,
};
},
created() {
setTimeout(() => this.toggleEl = false, 3000);
setTimeout(() => this.toggleEl = true, 6000);
},
render(h) {
return this.toggleEl ? h('div', this.$slots.default) : null
}
};
const SlotComponent = {
template: `
<div>
<slot></slot>
<div v-if="$slots.other">
<slot name="other"></slot>
</div>
</div>
`
}
const ParentComponent = {
template: `
<ToggleComponent>
<SlotComponent>
<template v-slot:default>
I should have an element below me
</template>
<template v-slot:other>
I am the element below you
</template>
</SlotComponent>
</ToggleComponent>
`,
components: {
ToggleComponent,
SlotComponent
},
}
var demo = new Vue({
el: '#demo',
template: `
<ParentComponent/>
`,
components: {
ParentComponent
},
});