Only show slot if it has content

后端 未结 6 1335
感情败类
感情败类 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:32

    It should be available at

    this.$slots.footer
    

    So, this should work.

    hasFooterSlot() {
      return !!this.$slots.footer
    }
    

    Example.

提交回复
热议问题