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>
属性
名字 | 类型 | 默认值 | 说明 | 版本要求 |
value | number | 时间,秒为单位 | -- | |
start | boolean | true | 是否开始计数 | -- |