使用slot卡槽,就是模板方法模式

    1. // parent.vue
    2. <template>
    3. <div>
    4. <div name="tom"></div>
    5. <div name="joe">
    6. <!--vue中的插槽渲染children-->
    7. <slot />
    8. </div>
    9. </div>
    10. </template>
    // stage.vue
    <template>
      <div>
        <parent>
          <!-- children的具体实现 -->
          <div>child</div>
        </parent>
      </div>
    </template>
    

    进阶

    // AnimalTemplate.vue
    <template>
      <div>
        <slot name="head"></slot>
        <slot name="body"></slot>
        <slot name="foot"></slot>
      </div>
    </template>
    
    // stage.vue
    <template>
      <div>
        <animal-template>
          <div slot="head">pig head</div>
          <div slot="body">pig body</div>
          <div slot="foot">pig foot</div>
        </animal-template>
        <animal-template>
          <div slot="head">chicken head</div>
          <div slot="body">chicken body</div>
          <div slot="foot">chicken foot</div>
        </animal-template>
      </div>
    </template>