99re热这里只有精品视频,7777色鬼xxxx欧美色妇,国产成人精品一区二三区在线观看,内射爽无广熟女亚洲,精品人妻av一区二区三区

Vant CountDown 倒計時

2022-05-31 13:35 更新

引入

import Vue from 'vue';
import { CountDown } from 'vant';

Vue.use(CountDown);

代碼演示

基本用法

time屬性表示倒計時總時長,單位為毫秒

<van-count-down :time="time" />
export default {
  data() {
    return {
      time: 30 * 60 * 60 * 1000
    };
  }
}

自定義格式

通過format屬性設(shè)置倒計時文本的內(nèi)容

<van-count-down :time="time" format="DD 天 HH 時 mm 分 ss 秒" />

毫秒級渲染

倒計時默認(rèn)每秒渲染一次,設(shè)置millisecond屬性可以開啟毫秒級渲染

<van-count-down millisecond :time="time" format="HH:mm:ss:SS" />

自定義樣式

通過插槽自定義倒計時的樣式,timeData對象格式見下方表格

<van-count-down :time="time">
  <template v-slot="timeData">
    <span class="item">{{ timeData.hours }}</span>
    <span class="item">{{ timeData.minutes }}</span>
    <span class="item">{{ timeData.seconds }}</span>
  </template>
</van-count-down>

<style>
.item {
  display: inline-block;
  width: 22px;
  margin-right: 5px;
  color: #fff;
  font-size: 12px;
  text-align: center;
  background-color: #1989fa;
}
</style>

手動控制

通過 ref 獲取到組件實例后,可以調(diào)用start、pause、reset方法

<van-count-down
  ref="countDown"
  millisecond
  :time="3000"
  :auto-start="false"
  format="ss:SSS"
  @finish="finish"
/>
<van-grid clickable>
  <van-grid-item text="開始" icon="play-circle-o" @click="start" />
  <van-grid-item text="暫停" icon="pause-circle-o" @click="pause" />
  <van-grid-item text="重置" icon="replay" @click="reset" />
</van-grid>
import { Toast } from 'vant';

export default {
  methods: {
    start() {
      this.$refs.countDown.start();
    },
    pause() {
      this.$refs.countDown.pause();
    },
    reset() {
      this.$refs.countDown.reset();
    },
    finish() {
      Toast('倒計時結(jié)束');
    }
  }
}

API

Props

參數(shù)說明類型默認(rèn)值
time倒計時時長,單位毫秒number | string0
format時間格式stringHH:mm:ss
auto-start是否自動開始倒計時booleantrue
millisecond是否開啟毫秒級渲染booleanfalse

format 格式

格式說明
DD天數(shù)
HH小時
mm分鐘
ss秒數(shù)
S毫秒(1 位)
SS毫秒(2 位)
SSS毫秒(3 位)

Events

事件名說明回調(diào)參數(shù)
finish倒計時結(jié)束時觸發(fā)-
change v2.4.4倒計時變化時觸發(fā)timeData

Slots

名稱說明SlotProps
default自定義內(nèi)容timeData

timeData 格式

名稱說明類型
days剩余天數(shù)number
hours剩余小時number
minutes剩余分鐘number
seconds剩余秒數(shù)number
milliseconds剩余毫秒number

方法

通過 ref 可以獲取到 CountDown 實例并調(diào)用實例方法,詳見 組件實例方法

方法名說明參數(shù)返回值
start開始倒計時--
pause暫停倒計時--
reset重設(shè)倒計時,若auto-starttrue,重設(shè)后會自動開始倒計時--

常見問題

在 iOS 系統(tǒng)上倒計時不生效?

如果你遇到了在 iOS 上倒計時不生效的問題,請確認(rèn)在創(chuàng)建 Date 對象時沒有使用new Date('2020-01-01')這樣的寫法,iOS 不支持以中劃線分隔的日期格式,正確寫法是new Date('2020/01/01')。

對此問題的詳細(xì)解釋:stackoverflow。


實例演示

以上內(nèi)容是否對您有幫助:
在線筆記
App下載
App下載

掃描二維碼

下載編程獅App

公眾號
微信公眾號

編程獅公眾號