mirror of
https://gitee.com/vant-contrib/vant.git
synced 2025-04-06 03:57:59 +08:00
docs(CountDown): use composition api
This commit is contained in:
parent
a1de44c97a
commit
84b7e69d64
@ -19,11 +19,12 @@ app.use(CountDown);
|
|||||||
```
|
```
|
||||||
|
|
||||||
```js
|
```js
|
||||||
|
import { ref } from 'vue';
|
||||||
|
|
||||||
export default {
|
export default {
|
||||||
data() {
|
setup() {
|
||||||
return {
|
const time = ref(30 * 60 * 60 * 1000);
|
||||||
time: 30 * 60 * 60 * 1000,
|
return { time };
|
||||||
};
|
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
```
|
```
|
||||||
@ -79,7 +80,7 @@ export default {
|
|||||||
:time="3000"
|
:time="3000"
|
||||||
:auto-start="false"
|
:auto-start="false"
|
||||||
format="ss:SSS"
|
format="ss:SSS"
|
||||||
@finish="finish"
|
@finish="onFinish"
|
||||||
/>
|
/>
|
||||||
<van-grid clickable :column-num="3">
|
<van-grid clickable :column-num="3">
|
||||||
<van-grid-item text="Start" icon="play-circle-o" @click="start" />
|
<van-grid-item text="Start" icon="play-circle-o" @click="start" />
|
||||||
@ -92,19 +93,29 @@ export default {
|
|||||||
import { Toast } from 'vant';
|
import { Toast } from 'vant';
|
||||||
|
|
||||||
export default {
|
export default {
|
||||||
methods: {
|
setup() {
|
||||||
start() {
|
const countDown = ref(null);
|
||||||
this.$refs.countDown.start();
|
|
||||||
},
|
const start = () => {
|
||||||
pause() {
|
countDown.value.start();
|
||||||
this.$refs.countDown.pause();
|
};
|
||||||
},
|
const pause = () => {
|
||||||
reset() {
|
countDown.value.pause();
|
||||||
this.$refs.countDown.reset();
|
};
|
||||||
},
|
const reset = () => {
|
||||||
finish() {
|
countDown.value.reset();
|
||||||
|
};
|
||||||
|
const onFinish = () => {
|
||||||
Toast('Finished');
|
Toast('Finished');
|
||||||
},
|
};
|
||||||
|
|
||||||
|
return {
|
||||||
|
start,
|
||||||
|
pause,
|
||||||
|
reset,
|
||||||
|
onFinish,
|
||||||
|
countDown,
|
||||||
|
};
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
```
|
```
|
||||||
|
@ -25,11 +25,12 @@ app.use(CountDown);
|
|||||||
```
|
```
|
||||||
|
|
||||||
```js
|
```js
|
||||||
|
import { ref } from 'vue';
|
||||||
|
|
||||||
export default {
|
export default {
|
||||||
data() {
|
setup() {
|
||||||
return {
|
const time = ref(30 * 60 * 60 * 1000);
|
||||||
time: 30 * 60 * 60 * 1000,
|
return { time };
|
||||||
};
|
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
```
|
```
|
||||||
@ -93,7 +94,7 @@ export default {
|
|||||||
:time="3000"
|
:time="3000"
|
||||||
:auto-start="false"
|
:auto-start="false"
|
||||||
format="ss:SSS"
|
format="ss:SSS"
|
||||||
@finish="finish"
|
@finish="onFinish"
|
||||||
/>
|
/>
|
||||||
<van-grid clickable>
|
<van-grid clickable>
|
||||||
<van-grid-item text="开始" icon="play-circle-o" @click="start" />
|
<van-grid-item text="开始" icon="play-circle-o" @click="start" />
|
||||||
@ -106,19 +107,29 @@ export default {
|
|||||||
import { Toast } from 'vant';
|
import { Toast } from 'vant';
|
||||||
|
|
||||||
export default {
|
export default {
|
||||||
methods: {
|
setup() {
|
||||||
start() {
|
const countDown = ref(null);
|
||||||
this.$refs.countDown.start();
|
|
||||||
},
|
const start = () => {
|
||||||
pause() {
|
countDown.value.start();
|
||||||
this.$refs.countDown.pause();
|
};
|
||||||
},
|
const pause = () => {
|
||||||
reset() {
|
countDown.value.pause();
|
||||||
this.$refs.countDown.reset();
|
};
|
||||||
},
|
const reset = () => {
|
||||||
finish() {
|
countDown.value.reset();
|
||||||
|
};
|
||||||
|
const onFinish = () => {
|
||||||
Toast('倒计时结束');
|
Toast('倒计时结束');
|
||||||
},
|
};
|
||||||
|
|
||||||
|
return {
|
||||||
|
start,
|
||||||
|
pause,
|
||||||
|
reset,
|
||||||
|
onFinish,
|
||||||
|
countDown,
|
||||||
|
};
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
```
|
```
|
||||||
|
@ -30,7 +30,7 @@
|
|||||||
:time="3000"
|
:time="3000"
|
||||||
:auto-start="false"
|
:auto-start="false"
|
||||||
format="ss:SSS"
|
format="ss:SSS"
|
||||||
@finish="$toast(t('finished'))"
|
@finish="onFinish"
|
||||||
/>
|
/>
|
||||||
<van-grid clickable :column-num="3">
|
<van-grid clickable :column-num="3">
|
||||||
<van-grid-item icon="play-circle-o" :text="t('start')" @click="start" />
|
<van-grid-item icon="play-circle-o" :text="t('start')" @click="start" />
|
||||||
@ -41,50 +41,62 @@
|
|||||||
</template>
|
</template>
|
||||||
|
|
||||||
<script>
|
<script>
|
||||||
|
import { ref } from 'vue';
|
||||||
|
import Toast from '../../toast';
|
||||||
|
import { useTranslate } from '../../composables/use-translate';
|
||||||
|
|
||||||
export default {
|
export default {
|
||||||
i18n: {
|
i18n: {
|
||||||
'zh-CN': {
|
'zh-CN': {
|
||||||
|
reset: '重置',
|
||||||
|
pause: '暂停',
|
||||||
|
start: '开始',
|
||||||
|
finished: '倒计时结束',
|
||||||
millisecond: '毫秒级渲染',
|
millisecond: '毫秒级渲染',
|
||||||
customStyle: '自定义样式',
|
customStyle: '自定义样式',
|
||||||
customFormat: '自定义格式',
|
customFormat: '自定义格式',
|
||||||
manualControl: '手动控制',
|
manualControl: '手动控制',
|
||||||
formatWithDay: 'DD 天 HH 时 mm 分 ss 秒',
|
formatWithDay: 'DD 天 HH 时 mm 分 ss 秒',
|
||||||
reset: '重置',
|
|
||||||
pause: '暂停',
|
|
||||||
start: '开始',
|
|
||||||
finished: '倒计时结束',
|
|
||||||
},
|
},
|
||||||
'en-US': {
|
'en-US': {
|
||||||
|
reset: 'Reset',
|
||||||
|
pause: 'Pause',
|
||||||
|
start: 'Start',
|
||||||
|
finished: 'Finished',
|
||||||
millisecond: 'Millisecond',
|
millisecond: 'Millisecond',
|
||||||
customStyle: 'Custom Style',
|
customStyle: 'Custom Style',
|
||||||
customFormat: 'Custom Format',
|
customFormat: 'Custom Format',
|
||||||
manualControl: 'Manual Control',
|
manualControl: 'Manual Control',
|
||||||
formatWithDay: 'DD Day, HH:mm:ss',
|
formatWithDay: 'DD Day, HH:mm:ss',
|
||||||
reset: 'Reset',
|
|
||||||
pause: 'Pause',
|
|
||||||
start: 'Start',
|
|
||||||
finished: 'Finished',
|
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
|
||||||
data() {
|
setup() {
|
||||||
return {
|
const t = useTranslate();
|
||||||
time: 30 * 60 * 60 * 1000,
|
const time = ref(30 * 60 * 60 * 1000);
|
||||||
|
const countDown = ref(null);
|
||||||
|
|
||||||
|
const start = () => {
|
||||||
|
countDown.value.start();
|
||||||
|
};
|
||||||
|
const pause = () => {
|
||||||
|
countDown.value.pause();
|
||||||
|
};
|
||||||
|
const reset = () => {
|
||||||
|
countDown.value.reset();
|
||||||
|
};
|
||||||
|
const onFinish = () => {
|
||||||
|
Toast(t('finished'));
|
||||||
};
|
};
|
||||||
},
|
|
||||||
|
|
||||||
methods: {
|
return {
|
||||||
start() {
|
time,
|
||||||
this.$refs.countDown.start();
|
start,
|
||||||
},
|
pause,
|
||||||
|
reset,
|
||||||
pause() {
|
onFinish,
|
||||||
this.$refs.countDown.pause();
|
countDown,
|
||||||
},
|
};
|
||||||
|
|
||||||
reset() {
|
|
||||||
this.$refs.countDown.reset();
|
|
||||||
},
|
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
</script>
|
</script>
|
||||||
|
Loading…
x
Reference in New Issue
Block a user