Answer the question
In order to leave comments, you need to log in
How not to render a slot until it is needed?
Imagine that in some component, another component is called that uses the slot from the first one, in an area that is not always displayed.
But the problem is that in this case, the slot is still rendered in the first component, although it will not be displayed.
For understanding, I made a very simple component:
<script type="text/x-template" id="foldet-block">
<div>
<span class="btn-link" v-on:click="toggle">{{anchor_text}}</span>
<div v-if="state.show"><slot></slot></div>
</div>
</script>
<script>
Vue.component('foldet-block', {
props: {
show: {type: Boolean, default: false},
anchor: {type: String},
anchor_show: {type: String, default: ''},
},
data () {
return {
state: {
show: false
},
}
},
created () {
this.state.show = this.show
},
computed: {
anchor_text () {
return this.state.show?this.anchor:(this.anchor_show?this.anchor_show:this.anchor)
}
},
methods: {
toggle () {
this.state.show = !this.state.show;
}
},
template: '#foldet-block'
});
</script>
<foldet-block
v-bind:anchor="'показать'"
v-bind:anchor_show="'скрыть'"
><p>{{text}}</p></foldet-block>
Answer the question
In order to leave comments, you need to log in
<foldet-block
v-bind:anchor="'показать'"
v-bind:anchor_show="'скрыть'"
><template v-slot><p>{{text}}</p></template></foldet-block>
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question