目录
当前位置: 首页 > 文档资料 > VUX 中文文档 >

Countdown 组件使用教程

优质
小牛编辑
136浏览
2023-12-01

安装

import { Countdown } from 'vux'

export default {
  components: {
    Countdown
  }
}
// 在入口文件全局引入

import Vue from 'vue'
import { Countdown } from 'vux'

Vue.component('countdown', Countdown)

自动倒计时

<template>
  <div>
    <group :title=" $t('Automatic countdown') ">
      <cell title="15s" v-model="value">
        <countdown v-model="time" @on-finish="finish" v-show="show"></countdown>
      </cell>
    </group>
  </div>
</template>

<script>
import { Countdown, Group, Cell } from 'vux'

export default {
  components: {
    Countdown,
    Cell,
    Group
  },
  data () {
    return {
      show: true,
      time: 15,
      value: ''
    }
  },
  methods: {
    finish (index) {
      this.show = false
      this.value = 'completed'
      console.log('current index', index)
    }
  }
}
</script>

手动模式

<template>
  <div>
    <group :title=" $t('Manually') ">
      <x-switch :title=" $t('Start') " v-model="start"></x-switch>
      <cell title="15s">
        <countdown v-model="time" :start="start" @on-finish="finish"></countdown>
      </cell>
    </group>
  </div>
</template>

<script>
import { Countdown, Group, Cell, XSwitch } from 'vux'

export default {
  components: {
    Countdown,
    Cell,
    Group,
    XSwitch
  },
  data () {
    return {
      time: 15,
      value: '',
      start: false
    }
  },
  methods: {
    finish (index) {
      this.start = false
      this.time = 20
    }
  }
}
</script>

属性

名字类型默认值说明版本要求
valuenumber时间,秒为单位--
startbooleantrue是否开始计数--