微信小程序 MinUI 組件庫系列之 abnor 異常流組件

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

abnor

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

abnor

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

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

npm install -g @mindev/min-cli

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

min init my-project

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

三、安裝 abnor 組件。npm

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

cd my-project

安裝組件:微信小程序

min install @minui/wxc-abnor

四、開啓dev。bash

min dev

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

五、在頁面中引入組件。

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

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

wxc-abnor 即爲異常流組件的標籤名,能夠在 wxml 中使用。

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

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

<wxc-abnor type="SHOP"></wxc-abnor>

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

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

<!-- home/index.wxp -->
<template>
  <wxc-abnor type="SHOP"></wxc-abnor>
</template>

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

<style>
</style>

圖示:

shop

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

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

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

Abnor【props】

名稱 描述
type [說明]:異常狀態類型,其優先級低於其餘屬性。
[類型]:String
默認值:""
[可選值]:REQUEST_ERROR, NOT_FOUND, DATA, FOLLOW, FEED,SHOP, WEIBO, SEARCH, TAG, MESSAGE, LIVE, ORDER, CART, FOOTPRINT, COUPON
image [說明]:背景圖。若與 type 同時指定,將覆蓋 type 對應的 image
[類型]:String
[默認值]:""
title [說明]:標題。若與 type 同時指定,將覆蓋 type 對應的 title
[類型]:String
[默認值]:""
tip [說明]:副標題。若與 type 同時指定,將覆蓋 type 對應的 tip
[類型]:String
[默認值]:""
button [說明]:按鈕文案。若與 type 同時指定,將覆蓋 type 對應的 button
[類型]:String
[默認值]:""
bindabnortap [說明]:按鈕事件。若配置了 button 屬性,則須要指定事件。其中 REQUEST_ERROR, NOT_FOUND 兩種 type 中均設置了默認的按鈕文案

更多demo

一、網絡異常

<template>
  <wxc-abnor type="REQUEST_ERROR" bind:abnortap="onAbnorTap"></wxc-abnor>
</template>

<script>
export default {
  config: {
    usingComponents: {
      'wxc-abnor': '@minui/wxc-abnor'
    }
  },
  data: {},
  onAbnorTap() {
      wx.showToast({
        title: 'success',
        duration: 2000
      });
    }
}
</script>

<style>
</style>

圖示:

網絡異常

二、頁面不存在

<template>
  <wxc-abnor type="NOT_FOUND" bind:abnortap="onAbnorTap"></wxc-abnor>
</template>

<script>
  export default {
    config: {
      usingComponents: {
        'wxc-abnor': '@minui/wxc-abnor'
      }
    },
    data: {},
    onAbnorTap() {
        wx.showToast({
          title: 'back',
          duration: 2000
        });
      }
  }
</script>

<style>
</style>

圖示:

頁面不存在

三、自定義數據

<template>
  <wxc-abnor
    type="REQUEST_ERROR"
    image="{{image}}"
    title="{{title}}"
    tip="{{tip}}"
    button="{{button}}"
    bind:abnortap="onAbnorTap"
  ></wxc-abnor>
</template>

<script>
  export default {
    config: {
      usingComponents: {
        'wxc-abnor': '@minui/wxc-abnor'
      }
    },
    data: {
      image: 'https://s10.mogucdn.com/p2/161213/upload_76h1c5hjc8heecjehlfgekjdl2ki0_514x260.png',
      title: '自定義標題',
      tip: '自定義副標題',
      button: '點我'
    },
    onAbnorTap() {
        wx.showToast({
          title: 'custom',
          duration: 2000
        });
      }
  }
</script>

<style>
</style>

圖示:

自定義數據

四、空數據狀態

<template>
  <wxc-abnor type="DATA"></wxc-abnor>
</template>

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

<style>
</style>

圖示:

空數據

五、無關注數據

<template>
  <wxc-abnor type="FOLLOW"></wxc-abnor>
</template>

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

<style>
</style>

圖示:

無關注數據

六、無反饋數據

<template>
  <wxc-abnor type="FOLLOW"></wxc-abnor>
</template>

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

<style>
</style>

圖示:

無反饋數據

七、無搜索數據

<template>
  <wxc-abnor type="SEARCH"></wxc-abnor>
</template>

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

<style>
</style>

圖示:

無搜索數據

八、無消息通知

<template>
  <wxc-abnor type="FOLLOW"></wxc-abnor>
</template>

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

<style>
</style>

圖示:

無消息通知

九、空訂單列表

<template>
  <wxc-abnor type="ORDER"></wxc-abnor>
</template>

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

<style>
</style>

圖示:

空訂單列表

十、空購物車

<template>
  <wxc-abnor type="CART"></wxc-abnor>
</template>

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

<style>
</style>

圖示:

空購物車

十一、空足跡

<template>
  <wxc-abnor type="FOOTPRINT"></wxc-abnor>
</template>

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

<style>
</style>

圖示:

空足跡

十二、無優惠券數據

<template>
  <wxc-abnor type="COUPON"></wxc-abnor>
</template>

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

<style>
</style>

圖示:

無優惠券數據

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

溝通反饋

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

羣二維碼

相關連接

開源組件

蘑菇街前端團隊,2018.01.23 於杭州
相關文章
相關標籤/搜索