vue3 template

template 使用情况
1. 根据某个状态渲染多个模板的  v-if v-else
2. 插槽的场景

插槽:
子组件写法:name="title"

<slot name="title" v-bind="{ row: typeItem, index: index }">
        <div class="menuItemBox">{{ typeItem.name }}</div>
</slot>

父组件调用写法:<template #title="{ row, index }">

<CompanyTypeNav :typeList="menuList" :activity="activity" url="">
     <template #title="{ row, index }">
       <div class="leftItem" @click="clickChange(row, index)">{{ row.name }} </div>
       <span
         class="startIcon"
         :class="{ active: row.isFollow }"
         @click="startHandle(row)"
       ></span>
     </template>
</CompanyTypeNav>

父组件

<FullWidth
    class="detailPage"
    :class="{ whiteBg: direData.length > 0 }"
    :otherBreadcrumb="otherBreadcrumb"
  >
    <template #header>
      <div class="headerDetail" :class="{ spec: (detailData?.title?.length || 0) > 20 }">
        <div class="txtBox">
          <h4>{{ detailData.title }}</h4>
          <a-popover
            placement="bottomRight"
            :destroyTooltipOnHide="true"
            trigger="hover"
            :overlayClassName="overLayClass"
          >
            <template #content>
              {{ detailData.excerpt }}
            </template>
            <p class="introduceTxt">
              <span> {{ detailData.excerpt }}</span>
            </p>
          </a-popover>
        </div>
        <div class="videoBox" @click="viewVideo" v-if="detailData?.videoPlayList?.length > 0">
          <img class="videoBg" src="/src/assets/images/knowledge/detail/videoImg.png" alt="" />
        </div>
        <div class="imgBg" v-else>
          <img :src="detailData?.cover" alt="" />
        </div>
      </div>
    </template>
    <template #content>
      <!-- 文章模块 -->
      <ContextBody
        :contentData="contentData"
        :direData="direData"
        :isThumbUp="isThumbUp"
        :isCollect="isCollect"
        @click-handle="clickHandle"
        :numData="{
          ...handledNum,
          comment: commentTotal,
        }"
        @embed-is-show="embedIsShowHandle"
        ref="contextRef"
      />
      <ThumbUpAndCollect
        @click-handle="clickHandle"
        :isThumbUp="isThumbUp"
        :isCollect="isCollect"
        :numData="{
          ...handledNum,
          comment: commentTotal > 9999 ? '1万+' : commentTotal,
        }"
        v-if="!embedIsShow"
        position="fixed"
      />
      <!-- 评论区 -->
      <Comment ref="commentsRef" :resourceType="1" :moduleType="3" />
      <Modal :modalData="modalData" v-if="modalData.show">
        <template #content>
          <div style="width: 100%; height: 500px">
            <Video :videoId="modalData.rowData.videoVid" />
          </div>
        </template>
      </Modal>
    </template>
  </FullWidth>

子组件

<template>
  <div class="FullWidthBox whiteBg" :class="'is' + [getLayoutContentMode]">
    <div class="headerContent" id="headerContent">
      <div class="header-breadcrumb">
        <a-breadcrumb separator=">">
          <a-breadcrumb-item v-for="(route, index) in routerData" :key="route.path">
            <span v-if="!route.redirect"> {{ t(route.meta.title) }}</span>
            <a href="javascript:;" @click="handleClick(route, Number(index) + 1)" v-else>{{
              t(route.meta.title)
            }}</a>
          </a-breadcrumb-item>
          <a-breadcrumb-item
            v-for="(otherItem, otherIndex) in otherBreadcrumb.filter(
              (item) => item.title !== undefined,
            )"
            :key="otherItem.title"
          >
            <a
              href="javascript:;"
              v-if="otherItem.path"
              @click="handleClick(otherItem, otherIndex + 2)"
              >{{ otherItem.title }}</a
            >
            <span v-else>{{ otherItem.title }}</span>
          </a-breadcrumb-item>
        </a-breadcrumb>
        <GoBack />
      </div>

      <slot name="header"></slot>
    </div>
    <div class="contentBox" id="contentBox">
      <slot name="content"></slot>
    </div>
  </div>
</template>
  • 1
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值