微信小程序 MinUI 組件庫系列之 progress 進度條組件

MinUI 是基於微信小程序自定義組件特性開發而成的一套簡潔、易用、高效的組件庫,適用場景廣,覆蓋小程序原生框架、各類小程序組件主流框架等,而且提供了高效的命令行工具。MinUI 組件庫包含了不少基礎的組件,其中 progress 進度條組件是一個很經常使用的基礎元件, MinUI 中 progress 組件的效果圖以下:javascript

progress

各式各樣的類型都有哦,是否是看起來很方便很快捷的樣子(^_^)。能夠打開微信掃一掃下面的小程序二維碼先一睹爲快:html

progress

下面介紹 progress 組件的使用方式。前端

一、使用下列命令安裝 Min-Cli,如已安裝,請進入到下一步。Min-Cli 的文檔請猛戳這裏:Min-Cli使用手冊java

npm install -g @mindev/min-cli

二、初始化一個小程序項目。git

min init my-project

選擇 新建小程序 選項,便可初始化一個小程序項目。建立項目後,在編輯器中打開項目,src 目錄爲源碼目錄,dist 目錄爲編譯後用於在微信開發者工具中指定的目錄。新建的項目中已有一個 home 頁面。詳細文檔:Min 初始化小程序項目github

三、安裝 progress 組件。npm

進入剛纔新建的小程序項目的目錄中:小程序

cd my-project

安裝組件:微信小程序

min install @minui/wxc-progress

四、開啓dev。bash

min dev

開啓以後,修改源碼後都會從新編譯。

五、在頁面中引入組件。

在編輯器中打開 src/pages 目錄下的 home/index.wxp 文件,在 script 中添加 config 字段,配置小程序自定義組件字段,代碼以下:

export default {
    config: {
        "usingComponents": {
            'wxc-progress': "@minui/wxc-progress"
        }
    }
}

wxc-progress 即爲頭像組件的標籤名,能夠在 wxml 中使用。

六、在 wxml 中使用 wxc-progress標籤。

home/index.wxp 文件的 template 中添加 wxc-progress 標籤,代碼以下:

<wxc-progress percent="80"></wxc-progress>

七、打開微信開發者工具,指定 dist 目錄,預覽項目。

home/index.wxp 文件的代碼以下所示:

<!-- home/index.wxp -->
<template>
  <wxc-progress percent="80"></wxc-progress>
</template>

<script>
export default {
  config: {
    usingComponents: {
      'wxc-progress': '@minui/wxc-progress'
    }
  },
  data: {}
}
</script>

<style>
</style>

圖示:

default

至此,minui 組件庫的 progress 進度條組件在 Min 工具生成的小程序項目中的方法已介紹完畢,其餘場景,在原生小程序或其餘小程序框架項目中的使用方式請移步至以下連接:

在已有小程序項目中使用 MinUI 組件介紹

瞭解組件的使用方式後,下面開始介紹 progress 組件的 API 。

Progress【props】

屬性 描述
percent [必填] 進度百分比
stroke-width [可選] 進度條線的寬度,單位 rpx,默認值 16
active-color [可選] 高亮態進度條的顏色,支持純色與線性漸變色。默認值 "#ffca49, #ffb262"。若只填一個色值,則進度條顯示爲該純色值。
background-color [可選] 進度條背景色,默認值 "#e5e5e5"
radius [可選] 圓角角度,單位 rpx, 默認值 15

更多demo

一、設置進度條的寬度

<template>
  <wxc-progress stroke-width="20"></wxc-progress>
</template>

<script>
export default {
  config: {
    usingComponents: {
      'wxc-progress': '@minui/wxc-progress'
    }
  },
  data: {}
}
</script>

<style>
</style>

圖示:

設置寬度

二、設置進度條的前景色

<template>
  <wxc-progress percent="60" active-color="#ac89ff"></wxc-progress>
</template>

<script>
export default {
  config: {
    usingComponents: {
      'wxc-progress': '@minui/wxc-progress'
    }
  },
  data: {}
}
</script>

<style>
</style>

圖示:

設置前景色

三、設置漸變的前景色

<template>
  <wxc-progress percent="60" active-color="#ac89ff,#ff76a2"></wxc-progress>
</template>

<script>
export default {
  config: {
    usingComponents: {
      'wxc-progress': '@minui/wxc-progress'
    }
  },
  data: {}
}
</script>

<style>
</style>

圖示:

漸變的前景色

四、設置背景色

<template>
  <wxc-progress percent="40" background-color="#eaffea"></wxc-progress>
</template>

<script>
export default {
  config: {
    usingComponents: {
      'wxc-progress': '@minui/wxc-progress'
    }
  },
  data: {}
}
</script>

<style>
</style>

圖示:

設置背景色

五、設置圓角弧度

<template>
  <wxc-progress radius="5"></wxc-progress>
</template>

<script>
export default {
  config: {
    usingComponents: {
      'wxc-progress': '@minui/wxc-progress'
    }
  },
  data: {}
}
</script>

<style></style>

圖示:

設置圓角弧度

更多組件更新同步請關注 MinUI 小程序組件庫示例查看,或請移步到實時同步更新的 微信小程序 progress 進度條組件使用文檔

溝通反饋

請添加羣助手 wUf18018252882 好友或者掃碼加好友,並與羣助手對話發送驗證碼 10088 按照指引進羣。

羣二維碼

相關連接

開源組件


蘑菇街前端團隊,2018.01.19 於杭州

相關文章
相關標籤/搜索