最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

uniapp項目實踐自定義加載組件示例詳解

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

準備工作

有時候一個頁面請求接口需要加載很長時間,這時候就需要一個加載頁面來告知用戶內容正在請求加載中,下面就寫一個簡單的自定義加載組件。

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

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

邏輯思路

編寫模板部分

要求具有擴展性,因此可以使用slot插槽來插入內容,也方便后期修改自定義。

使用classstyle綁定一些父組件傳過來的值,更加個性化。

這個頁面分為圖標和文本提示兩部分,各自可以自定義顯示、大小、顏色。

編寫樣式部分

這部分就是圖標和文本的樣式以及一些加載動畫的內容。

編寫腳本部分

這部分主要是父組件傳遞過來的參數(shù),通過props進行制定格式。

實戰(zhàn)演練

下面就簡單實現(xiàn)一個加載組件。

模板部分

<view
  class="q-loading"
  :style="{'backgroundColor': props.bgColor}"
  v-if="props.show"
>
  <view class="q-loading-inner">
    <slot name="load">
      <!-- 圖標部分 -->
      <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>
          <!-- 旋轉 -->
          <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>

樣式部分

這部分就是頁面的樣式以及三個對應的動畫。

  • 頁面的樣式
.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;
        }
      }
    }
  }
}
  • 三個對應的動畫
// 圓環(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%);
  }
}
// 轉動
@keyframes loadingCircleRound {
  to {
    transform: rotate(1turn);
  }
}

腳本部分

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

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

效果預覽

下面看一下預覽效果吧。

圓環(huán)效果

呼吸效果

旋轉效果

最后

以上就是自定義加載組件的主要內容,更多關于uniapp自定義加載組件的資料請關注腳本之家其它相關文章!

相關文章

  • 詳解如何用JavaScript編寫一個單元測試

    詳解如何用JavaScript編寫一個單元測試

    測試代碼是確保代碼穩(wěn)定的第一步。能做到這一點的最佳方法之一就是使用單元測試。這篇文章主要介紹了如何用JavaScript編寫你的第一個單元測試,感興趣的可以了解一下
    2022-11-11
  • Javascript實現(xiàn)hashcode函數(shù)實現(xiàn)對象比較與原理說明

    Javascript實現(xiàn)hashcode函數(shù)實現(xiàn)對象比較與原理說明

    在JavaScript中,數(shù)值的比較是比較簡單的,使用相等(==)和全等(===)符號基本上可以解決大多數(shù)非對象的比較。但是相等(==)和全等(===)符號在對象 object 的比較上,就不能滿足所有的要求了
    2023-06-06
  • JavaScript在IE和Firefox瀏覽器下的7個差異兼容寫法小結

    JavaScript在IE和Firefox瀏覽器下的7個差異兼容寫法小結

    盡管那需要用長串的、沉悶的不同分支代碼來應付不同瀏覽器的日子已經(jīng)過去,偶爾還是有必要做一些簡單的區(qū)分和目標檢測來確保某塊代碼能在用戶的機器上正常運行。
    2010-06-06
  • Javascript?、Vue禁止鼠標右鍵點擊事件實例

    Javascript?、Vue禁止鼠標右鍵點擊事件實例

    這篇文章主要給大家介紹了關于Javascript?、Vue禁止鼠標右鍵點擊事件的相關資料,禁止右鍵的原理是通過JavaScript阻止瀏覽器右鍵事件的默認行為,從而達到禁止右鍵的效果,文中通過代碼介紹的非常詳細,需要的朋友可以參考下
    2023-11-11
  • newxtree.js代碼

    newxtree.js代碼

    newxtree.js代碼...
    2007-03-03
  • js中實現(xiàn)繼承的五種方法

    js中實現(xiàn)繼承的五種方法

    這篇文章主要介紹了js中實現(xiàn)繼承的五種方法,幫助大家更好的理解和使用JavaScript,感興趣的朋友可以了解下
    2021-01-01
  • JavaScript中Dom模型和Bom模型舉例詳解

    JavaScript中Dom模型和Bom模型舉例詳解

    DOM和BOM是Web開發(fā)中的兩個重要模型,這篇文章主要給大家介紹了關于JavaScript中Dom模型和Bom模型的相關資料,文中通過代碼介紹的非常詳細,需要的朋友可以參考下
    2025-06-06
  • 使用Three.js制作一個3D獎牌頁面

    使用Three.js制作一個3D獎牌頁面

    本文將使用React+Three.js技術棧,制作一個專屬的3D獎牌頁面,文中的示例代碼講解詳細,感興趣的小伙伴可以跟隨小編一起動手試一試
    2022-01-01
  • bootstrap日歷插件datetimepicker使用方法

    bootstrap日歷插件datetimepicker使用方法

    這篇文章主要為大家詳細介紹了bootstrap日歷datetimepicker插件的使用方法,具有一定的參考價值,感興趣的小伙伴們可以參考一下
    2016-12-12
  • ES6 Array常用擴展的應用實例分析

    ES6 Array常用擴展的應用實例分析

    這篇文章主要介紹了ES6 Array常用擴展的應用,結合實例形式分析各種常見擴展方法針對Array數(shù)組的轉換、遍歷、查找、運算等相關操作技巧,需要的朋友可以參考下
    2019-06-06

最新評論

乌海市| 故城县| 句容市| 溆浦县| 延安市| 将乐县| 界首市| 如皋市| 江源县| 乌兰浩特市| 迁西县| 孟村| 长武县| 志丹县| 湘潭市| 佳木斯市| 牡丹江市| 灌云县| 论坛| 长顺县| 丹巴县| 石狮市| 麻栗坡县| 天门市| 海南省| 石首市| 唐山市| 洪江市| 芷江| 阳山县| 宁河县| 夏邑县| 黄大仙区| 洪湖市| 房产| 永安市| 吴堡县| 凉城县| 连州市| 泾源县| 霍林郭勒市|