Only show slot if it has content

后端 未结 6 1381
感情败类
感情败类 2021-01-30 20:00

Is there a way to only display a slot if it has any content?

For example, I\'m building a simple Card.vue component, and I only want the footer displayed if

6条回答
  •  情深已故
    2021-01-30 20:11

    You should check vm.$slots and also vm.$scopedSlots for it.

    hasSlot (name = 'default') {
       return !!this.$slots[ name ] || !!this.$scopedSlots[ name ];
    }
    

提交回复
热议问题