国产chinesehdxxxx野外,国产av无码专区亚洲av琪琪,播放男人添女人下边视频,成人国产精品一区二区免费看,chinese丰满人妻videos

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屬性設置倒計時文本的內容

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

毫秒級渲染

倒計時默認每秒渲染一次,設置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 獲取到組件實例后,可以調用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('倒計時結束');
    }
  }
}

API

Props

參數(shù)說明類型默認值
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

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

Slots

名稱說明SlotProps
default自定義內容timeData

timeData 格式

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

方法

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

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

常見問題

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

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

對此問題的詳細解釋:stackoverflow。


實例演示

以上內容是否對您有幫助:
在線筆記
App下載
App下載

掃描二維碼

下載編程獅App

公眾號
微信公眾號

編程獅公眾號