uniapp解讀代碼

引言 學(xué)習(xí)uniapp代碼解讀
  • (一)swiper中的多個組件ref存儲

<swiper class="swiper" :current-item-id="current" @change="handleSwiperChange">
  <swiper-item v-for="item of tabHeaderDataList" :key="item.id" :item-id="item.id">
    <view class="swiper-item">
      <ContractList
        :filterFormData="filterFormData"
        :itemId="item.id"
        :item="item"
        :currentTab="current"
        :contractCode="getContractCode"
        @operClick="handleOperClick"
        @detailClick="handleDetailClick"
        @emitCountData="emitCountData"
        ref="ContractListRef"
      />
    </view>
  </swiper-item>
</swiper>
const ContractListRef = ref<InstanceType<typeof ContractList>[]>();

(1) typeof ContractList:獲取 ContractList 的類型(通常是一個 Vue 組件)。

InstanceType<...>:獲取該組件的實例類型。
(2)ContractLis組件內(nèi)部進(jìn)行暴露,外部變可以調(diào)用
defineExpose({
openDialog,
renderData,
openFilter,
resetBatchSigning,
});
(3)外部調(diào)用
ContractListRef.value?.[0]?.openDialog(current.value);
ContractListRef.value?.[0]?.openFilter(curTabIndex.value);

  • (二)swiper 和 List 列表嵌套

  <view class="main">
    <view class="header" id="header">
      <view class="header-tabList">
        <SdpTabs
          class="component-stretch-hidden"
          :list="tabHeaderDataList"
          @change="onChange"
          :current="curTabIndex"
        ></SdpTabs>
      </view>
      <view
        class="header-filterBtn"
        :class="{ active: computedFilterActive }"
        @click="openFilter = true"
        >篩選</view
      >
    </view>
    <view class="content">
      <swiper class="swiper" :current-item-id="current" @change="handleSwiperChange">
        <swiper-item v-for="item of tabHeaderDataList" :key="item.id" :item-id="item.id">
          <view class="swiper-item">
            <ContractList
              :filterFormData="filterFormData"
              :itemId="item.id"
              :item="item"
              :currentTab="current"
              :contractCode="getContractCode"
              @operClick="handleOperClick"
              @detailClick="handleDetailClick"
              @emitCountData="emitCountData"
              ref="ContractListRef"
            />
          </view>
        </swiper-item>
      </swiper>
    </view>
    </view>
swiper嵌套列表高度css布局
.main {
 width: 100%;
 height: 100vh;
 overflow: hidden;
 display: flex;
 flex-direction: column;
 background-image: url('https://pro-sdp-oss.aitojoy.com/fe/tojoy-sdp-employee/image/nav-bar-bg_20240516_1513.png');
 background-repeat: no-repeat;
 background-size: contain;
 background-color: #f5f7fa;
 //padding-bottom: constant(safe-area-inset-bottom);
 //padding-bottom: env(safe-area-inset-bottom);
 .header {
   display: flex;
   align-items: center;
   &-tabList {
     flex: 1;
   }
   &-filterBtn {
     width: auto;
     height: 100%;
     padding: 0 25rpx;
     font-size: 30rpx;
     color: rgba(0, 0, 0, 0.9);
     display: flex;
     align-items: center;
     &::before {
       content: '';
       background-image: url('https://pro-sdp-oss.aitojoy.com/fe/tojoy-sdp-employee/image/icon-filter_20240517_1012.png');
       width: 30rpx;
       height: 28rpx;
       background-size: cover;
     }
     &.active {
       color: #605ce5;
       font-weight: 500;
       &::before {
         background-image: url('https://pro-sdp-oss.aitojoy.com/fe/tojoy-sdp-employee/image/icon-checked-filter_20240618_1522.png');
       }
     }
   }
 }
 .content {
   // padding: 0 20rpx;
   flex: 1;
   overflow: hidden;
   .swiper {
     height: 100%;
     .swiper-item {
       height: 100%;
     }
   }
 }
}

1、 list組件內(nèi)部css
.scroll {
height: 100%;
padding-top: 20rpx;
padding-bottom: constant(safe-area-inset-bottom);
padding-bottom: env(safe-area-inset-bottom);
}
最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時請結(jié)合常識與多方信息審慎甄別。
平臺聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點,簡書系信息發(fā)布平臺,僅提供信息存儲服務(wù)。

相關(guān)閱讀更多精彩內(nèi)容

友情鏈接更多精彩內(nèi)容