CountDown 倒计时

使用指南

在 .json 中引入组件

  1. "usingComponents": {
  2. "i-count-down": "../../dist/count-down/index"
  3. }

示例

  1. <view class="view-wrap">
  2. <text class="type-title">倒计时:</text>
  3. <i-count-down
  4. target="{{targetTime}}"
  5. clear-timer="{{clearTimer}}"
  6. ></i-count-down>
  7. </view>
  8. <view class="view-wrap">
  9. <text class="type-title">显示天的倒计时:</text>
  10. <i-count-down
  11. target="{{targetTime1}}"
  12. show-day="{{true}}"
  13. clear-timer="{{clearTimer}}"
  14. ></i-count-down>
  15. </view>
  16. <view class="view-wrap">
  17. <text class="type-title">自定义格式倒计时:</text>
  18. <i-count-down
  19. target="{{targetTime}}"
  20. format="{{myFormat}}"
  21. clear-timer="{{clearTimer}}"
  22. ></i-count-down>
  23. </view>
  24. <view class="view-wrap">
  25. <text class="type-title">自定义格式倒计时:</text>
  26. <i-count-down
  27. target="{{targetTime1}}"
  28. show-day="{{true}}"
  29. format="{{myFormat1}}"
  30. clear-timer="{{clearTimer}}"
  31. ></i-count-down>
  32. </view>
  33. <view class="view-wrap">
  34. <text class="type-title">执行回调的倒计时:</text>
  35. <i-count-down
  36. target="{{targetTime2}}"
  37. bindcallback="myLinsterner"
  38. clear-timer="{{clearTimer}}"
  39. ></i-count-down>
  40. <text>倒计时状态:{{status}}</text>
  41. </view>
  42. <view class="view-wrap">
  43. <text class="type-title">修改倒计时样式:</text>
  44. <i-count-down
  45. target="{{targetTime}}"
  46. countdown-class="big"
  47. clear-timer="{{clearTimer}}"
  48. ></i-count-down>
  49. </view>
  1. Page({
  2. data: {
  3. targetTime: 0,
  4. targetTime1: 0,
  5. myFormat: ['时', '分', '秒'],
  6. myFormat1: ['天', '时', '分', '秒'],
  7. status: '进行中...',
  8. clearTimer: false
  9. },
  10. onLoad() {
  11. this.setData({
  12. targetTime: new Date().getTime() + 6430000,
  13. targetTime1: new Date().getTime() + 86430000,
  14. targetTime2: new Date().getTime() + 10000
  15. });
  16. },
  17. onUnload() {
  18. this.setData({
  19. clearTimer: true
  20. });
  21. },
  22. myLinsterner(e) {
  23. this.setData({
  24. status: '结束'
  25. });
  26. }
  27. });

API

CountDown properties

属性说明类型默认值
i-class自定义 class 类名String-
target目标时间Number-
show-day是否显示天数Booleanfalse
format时间格式化显示String-
clear-timer是否停止计时Booleanfalse

CountDown events

事件名说明返回值
bind:callback倒计时结束回调-