为什么未安装子组件?

时间:2018-06-29 22:07:58

标签: vuejs2 vue-component

为什么未安装子组件?

基本模板:

<TableComponent :data="data">

      <template slot="thead">
        <tr>
          <TableHeader></TableHeader>
        </tr>
      </template>

</TableComponent>

TableComponent

<template>

  <div>
    <table>
      <thead>
      {{ renderThead() }}
      </thead>
      <tbody>

      </tbody>
      <tfoot>

      </tfoot>
    </table>
  </div>

</template>

<script>

  export default {
    name: 'TableComponent',

    props: {
      data: {
        required: true,
        type: [Array, Function]
      },
      itemKey: {
        default: 'id',
      },
    },

    methods: {
      renderThead: function () {
        let method = this.$scopedSlots.thead
          ? this.$scopedSlots.thead
          : () => this.$slots.thead

        console.info(method())

        // return method();

      },
    },

  }
</script>

它是TableHeader组件:

<template>

  <th>
    {{ name }}
  </th>

</template>

<script>
  export default {
    name: 'TableHeader',

    props: {
      name: {
        type: String
      }
    },

    mounted() {
      console.info("MOUNTED")
    }
  }
</script>

关于TableHeader的控制台信息不起作用。 你有什么想法吗?

0 个答案:

没有答案
相关问题