欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

uniapp項(xiàng)目實(shí)踐自定義加載組件示例詳解

 更新時(shí)間:2023年09月06日 10:22:03   作者:MarkGuan  
這篇文章主要為大家介紹了uniapp項(xiàng)目實(shí)踐自定義加載組件示例詳解,有需要的朋友可以借鑒參考下,希望能夠有所幫助,祝大家多多進(jìn)步,早日升職加薪

準(zhǔn)備工作

有時(shí)候一個(gè)頁(yè)面請(qǐng)求接口需要加載很長(zhǎng)時(shí)間,這時(shí)候就需要一個(gè)加載頁(yè)面來(lái)告知用戶內(nèi)容正在請(qǐng)求加載中,下面就寫一個(gè)簡(jiǎn)單的自定義加載組件。

在之前的全局組件目錄components下新建一個(gè)組件文件夾,命名為q-loading,組件為q-loading.vue。

再找?guī)讉€(gè)效果不錯(cuò)的 css 加載動(dòng)畫,然后修改一下樣式。

邏輯思路

編寫模板部分

要求具有擴(kuò)展性,因此可以使用slot插槽來(lái)插入內(nèi)容,也方便后期修改自定義。

使用classstyle綁定一些父組件傳過(guò)來(lái)的值,更加個(gè)性化。

這個(gè)頁(yè)面分為圖標(biāo)和文本提示兩部分,各自可以自定義顯示、大小、顏色。

編寫樣式部分

這部分就是圖標(biāo)和文本的樣式以及一些加載動(dòng)畫的內(nèi)容。

編寫腳本部分

這部分主要是父組件傳遞過(guò)來(lái)的參數(shù),通過(guò)props進(jìn)行制定格式。

實(shí)戰(zhàn)演練

下面就簡(jiǎn)單實(shí)現(xiàn)一個(gè)加載組件。

模板部分

<view
  class="q-loading"
  :style="{'backgroundColor': props.bgColor}"
  v-if="props.show"
>
  <view class="q-loading-inner">
    <slot name="load">
      <!-- 圖標(biāo)部分 -->
      <view
        :class="{'q-loading-icon': true, 'pause': !props.show && !props.showIcon}"
        v-if="props.showIcon"
      >
        <slot name="icon">
          <!-- 圓環(huán) -->
          <view
            class="q-loading-item q-loading-circle"
            :style="{'width': props.borSize +'rpx', 'height': props.borSize +'rpx', 'borderWidth': props.borWin + 'rpx', 'borderColor': props.borColor, 'borderLeftColor': props.bordActiveColor}"
            v-if="props.iconName == 'circle'"
          >
          </view>
          <!-- 呼吸 -->
          <view
            class="q-loading-item q-loading-circle-breath"
            v-if="props.iconName == 'circle-breath'"
          >
          </view>
          <!-- 旋轉(zhuǎn) -->
          <view
            class="q-loading-item q-loading-circle-round"
            v-if="props.iconName == 'circle-round'"
          >
            <view
              class="loading-round"
              :style="{'backgroundColor': props.bordActiveColor}"
            ></view>
            <view
              class="loading-round"
              :style="{'backgroundColor': props.bordActiveColor}"
            ></view>
            <view
              class="loading-round"
              :style="{'backgroundColor': props.bordActiveColor}"
            ></view>
            <view
              class="loading-round"
              :style="{'backgroundColor': props.bordActiveColor}"
            ></view>
            <view
              class="loading-round"
              :style="{'backgroundColor': props.bordActiveColor}"
            ></view>
            <view
              class="loading-round"
              :style="{'backgroundColor': props.bordActiveColor}"
            ></view>
            <view
              class="loading-round"
              :style="{'backgroundColor': props.bordActiveColor}"
            ></view>
          </view>
        </slot>
      </view>
      <!-- 提示文本 -->
      <view
        class="q-loading-text"
        v-if="props.showText"
        :style="{'color': props.textColor, 'fontSize': props.textSize + 'rpx'}"
      >
        <slot name="text"> {{ props.text }} </slot>
      </view>
    </slot>
  </view>
</view>

樣式部分

這部分就是頁(yè)面的樣式以及三個(gè)對(duì)應(yīng)的動(dòng)畫。

  • 頁(yè)面的樣式
.q-loading {
  position: fixed;
  top: 0;
  left: 0;
  display: flex;
  justify-content: center;
  align-items: center;
  box-sizing: border-box;
  padding: 10rpx;
  width: 100%;
  height: 100vh;
  .q-loading-inner {
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    .q-loading-icon {
      display: flex;
      justify-content: center;
      align-items: center;
      margin-bottom: 10rpx;
      width: 100rpx;
      height: 100rpx;
      .q-loading-circle {
        border-radius: 50%;
        border-style: solid;
        animation: loadingCircle 1s linear infinite;
      }
      .q-loading-circle-breath {
        box-shadow: 0 0 0 0 rgb(204, 73, 152);
        height: 36px;
        width: 36px;
        border-radius: 50%;
        animation: loadingCircleBreath 1s linear infinite;
      }
      .q-loading-circle-round {
        position: relative;
        width: 75rpx;
        height: 75rpx;
        .loading-round {
          position: absolute;
          width: 26rpx;
          height: 26rpx;
          border-radius: 50%;
          animation: loadingCircleRound 3s ease infinite;
          transform-origin: 120% 80rpx;
          &.loading-round:nth-child(1) {
            z-index: 7;
          }
          &.loading-round:nth-child(2) {
            height: 12px;
            width: 12px;
            animation-delay: 0.2s;
            z-index: 6;
          }
          &.loading-round:nth-child(3) {
            height: 11px;
            width: 11px;
            animation-delay: 0.4s;
            z-index: 5;
          }
          &.loading-round:nth-child(4) {
            height: 10px;
            width: 10px;
            animation-delay: 0.6s;
            z-index: 4;
          }
          &.loading-round:nth-child(5) {
            height: 9px;
            width: 9px;
            animation-delay: 0.8s;
            z-index: 3;
          }
          &.loading-round:nth-child(6) {
            height: 8px;
            width: 8px;
            animation-delay: 1s;
            z-index: 2;
          }
          &.loading-round:nth-child(7) {
            height: 7px;
            width: 7px;
            animation-delay: 1.2s;
            z-index: 1;
          }
        }
      }
      &.pause {
        .q-loading-item {
          animation-play-state: paused;
        }
      }
    }
  }
}
  • 三個(gè)對(duì)應(yīng)的動(dòng)畫
// 圓環(huán)
@keyframes loadingCircle {
  0% {
    transform: rotate(0);
  }
  100% {
    transform: rotate(360deg);
  }
}
// 呼吸
@keyframes loadingCircleBreath {
  0% {
    transform: scale(0.3);
    box-shadow: 0 0 0 0 rgba(36, 175, 214, 60%);
  }
  60% {
    transform: scale(0.5);
    box-shadow: 0 0 0 56rpx rgba(36, 175, 214, 0%);
  }
  100% {
    transform: scale(0.3);
    box-shadow: 0 0 0 0 rgba(36, 175, 214, 0%);
  }
}
// 轉(zhuǎn)動(dòng)
@keyframes loadingCircleRound {
  to {
    transform: rotate(1turn);
  }
}

腳本部分

這部分就是傳遞的數(shù)據(jù),包括組件、圖標(biāo)和文本的顯示控制,以及各自的顏色,大小等參數(shù)。

const props = defineProps({
  // 顯示加載
  show: {
    type: Boolean,
    default: true,
  },
  // 背景色
  bgColor: {
    type: String,
    default: "#fff",
  },
  // 顯示圖標(biāo)
  showIcon: {
    type: Boolean,
    default: true,
  },
  // 名稱
  iconName: {
    type: String,
    default: "circle",
  },
  // 大小
  borSize: {
    type: Number,
    default: 60,
  },
  // 邊框粗細(xì)
  borWin: {
    type: Number,
    default: 8,
  },
  // 顏色
  borColor: {
    type: String,
    default: "#e3e3e3",
  },
  // 活動(dòng)顏色
  bordActiveColor: {
    type: String,
    default: "#24afd6",
  },
  // 顯示文本
  showText: {
    type: Boolean,
    default: true,
  },
  // 文本內(nèi)容
  text: {
    type: String,
    default: "加載中...",
  },
  // 文本顏色
  textColor: {
    type: String,
    default: "#555",
  },
  // 文本大小
  textSize: {
    type: Number,
    default: 20,
  },
});

效果預(yù)覽

下面看一下預(yù)覽效果吧。

圓環(huán)效果

呼吸效果

旋轉(zhuǎn)效果

最后

以上就是自定義加載組件的主要內(nèi)容,更多關(guān)于uniapp自定義加載組件的資料請(qǐng)關(guān)注腳本之家其它相關(guān)文章!

相關(guān)文章

最新評(píng)論