wxc-badge

MinUI 小程序组件 - 徽章

Install

  1. $ min install @minui/wxc-badge

Demos

默认姿势

徽章 badge - 图1

  1. <!-- in your page -->
  2. <template>
  3. <view class="user">
  4. <image class="user__avatar" src="https://s10.mogucdn.com/mlcdn/c45406/171019_21c2fgdl406e80id5fa5hdckkh804_356x356.png"></image>
  5. <wxc-badge class="user__un-read-msg-count">9</wxc-badge>
  6. </view>
  7. </template>
  8. <script>
  9. export default {
  10. config: {
  11. usingComponents: {
  12. 'wxc-badge': '@minui/wxc-badge'
  13. }
  14. },
  15. data: {},
  16. methods: {}
  17. }
  18. </script>
  19. <style>
  20. .user {
  21. width: 100rpx;
  22. height: 100rpx;
  23. position: relative;
  24. }
  25. .user__avatar {
  26. display: block;
  27. width: 100rpx;
  28. height: 100rpx;
  29. border-radius: 50%;
  30. }
  31. .user__un-read-msg-count {
  32. position: absolute;
  33. top: -16rpx;
  34. right: -8rpx;
  35. }
  36. </style>

红点模式

弱提示,显示为一个红点

徽章 badge - 图2

  1. <template>
  2. <view class="message">
  3. <image class="message__avatar" src="https://s10.mogucdn.com/mlcdn/c45406/171019_7i7cf28a75h4jac3hidkc4c3j4e7i_200x200.png"></image>
  4. <wxc-badge class="message__badge" type="dot">30</wxc-badge>
  5. </view>
  6. </template>
  7. <script>
  8. export default {
  9. config: {
  10. usingComponents: {
  11. 'wxc-badge': '@minui/wxc-badge'
  12. }
  13. },
  14. data: {},
  15. methods: {}
  16. }
  17. </script>
  18. <style>
  19. .message {
  20. width: 100rpx;
  21. height: 100rpx;
  22. position: relative;
  23. }
  24. .message__avatar {
  25. display: block;
  26. width: 100rpx;
  27. height: 100rpx;
  28. }
  29. .message__badge {
  30. position: absolute;
  31. top: -20rpx;
  32. right: -2rpx;
  33. }
  34. </style>

最大值边界

仅对 value 传值有效

徽章 badge - 图3

  1. <template>
  2. <view class="user">
  3. <image class="user__avatar" src="https://s10.mogucdn.com/mlcdn/c45406/171019_20e8ac6bcjb67f9i8b88j2aiiil03_200x200.jpg"></image>
  4. <wxc-badge class="user__un-read-msg-count" max="99" value="230"></wxc-badge>
  5. </view>
  6. </template>
  7. <script>
  8. export default {
  9. config: {
  10. usingComponents: {
  11. 'wxc-badge': '@minui/wxc-badge'
  12. }
  13. },
  14. data: {},
  15. methods: {}
  16. }
  17. </script>
  18. <style>
  19. .user {
  20. width: 100rpx;
  21. height: 100rpx;
  22. position: relative;
  23. }
  24. .user__avatar {
  25. display: block;
  26. width: 100rpx;
  27. height: 100rpx;
  28. border-radius: 50%;
  29. }
  30. .user__un-read-msg-count {
  31. position: absolute;
  32. top: -16rpx;
  33. right: -18rpx;
  34. }
  35. </style>

个性化支持

徽章 badge - 图4

  1. <template>
  2. <view class="message">
  3. <image class="message__avatar" src="https://s10.mogucdn.com/mlcdn/c45406/171019_7i7cf28a75h4jac3hidkc4c3j4e7i_200x200.png"></image>
  4. <wxc-badge class="message__badge">new</wxc-badge>
  5. </view>
  6. </template>
  7. <script>
  8. export default {
  9. config: {
  10. usingComponents: {
  11. 'wxc-badge': '@minui/wxc-badge'
  12. }
  13. },
  14. data: {},
  15. methods: {}
  16. }
  17. </script>
  18. <style>
  19. .message {
  20. width: 100rpx;
  21. height: 100rpx;
  22. position: relative;
  23. }
  24. .message__avatar {
  25. display: block;
  26. width: 100rpx;
  27. height: 100rpx;
  28. }
  29. .message__badge {
  30. position: absolute;
  31. top: -16rpx;
  32. right: -18rpx;
  33. }
  34. </style>

value 传值

优先级高于标签内嵌套值

徽章 badge - 图5

  1. <template>
  2. <view class="user">
  3. <image class="user__avatar" src="https://s10.mogucdn.com/mlcdn/c45406/171019_21c2fgdl406e80id5fa5hdckkh804_356x356.png"></image>
  4. <wxc-badge class="user__un-read-msg-count" value="100"></wxc-badge>
  5. </view>
  6. </template>
  7. <script>
  8. export default {
  9. config: {
  10. usingComponents: {
  11. 'wxc-badge': '@minui/wxc-badge'
  12. }
  13. },
  14. data: {},
  15. methods: {}
  16. }
  17. </script>
  18. <style>
  19. .user {
  20. width: 100rpx;
  21. height: 100rpx;
  22. position: relative;
  23. }
  24. .user__avatar {
  25. display: block;
  26. width: 100rpx;
  27. height: 100rpx;
  28. border-radius: 50%;
  29. }
  30. .user__un-read-msg-count {
  31. position: absolute;
  32. top: -16rpx;
  33. right: -18rpx;
  34. }
  35. </style>

API

Badge【props】

属性描述
value[可选] 设置数值,优先级会高于标签内嵌套值
max[可选] 设置最大边界,越界数值显示为 maxVal+
type[可选] 设置标记类型,职位 dot 显示为弱提示的圆点
地址
badge 组件文档 https://meili.github.io/min/docs/minui/index.html#badge
badge 组件源码 https://github.com/meili/minui/tree/master/packages/wxc-badge
MinUI 组件库 https://github.com/meili/minui

Preview

badge

ChangeLog

v1.0.2(2017.11.02)

  • update .npmignore

v1.0.1(2017.10.24)

  • 初始版本