docs(CountDown): use composition api
This commit is contained in:
@@ -25,11 +25,12 @@ app.use(CountDown);
|
||||
```
|
||||
|
||||
```js
|
||||
import { ref } from 'vue';
|
||||
|
||||
export default {
|
||||
data() {
|
||||
return {
|
||||
time: 30 * 60 * 60 * 1000,
|
||||
};
|
||||
setup() {
|
||||
const time = ref(30 * 60 * 60 * 1000);
|
||||
return { time };
|
||||
},
|
||||
};
|
||||
```
|
||||
@@ -93,7 +94,7 @@ export default {
|
||||
:time="3000"
|
||||
:auto-start="false"
|
||||
format="ss:SSS"
|
||||
@finish="finish"
|
||||
@finish="onFinish"
|
||||
/>
|
||||
<van-grid clickable>
|
||||
<van-grid-item text="开始" icon="play-circle-o" @click="start" />
|
||||
@@ -106,19 +107,29 @@ export default {
|
||||
import { Toast } from 'vant';
|
||||
|
||||
export default {
|
||||
methods: {
|
||||
start() {
|
||||
this.$refs.countDown.start();
|
||||
},
|
||||
pause() {
|
||||
this.$refs.countDown.pause();
|
||||
},
|
||||
reset() {
|
||||
this.$refs.countDown.reset();
|
||||
},
|
||||
finish() {
|
||||
setup() {
|
||||
const countDown = ref(null);
|
||||
|
||||
const start = () => {
|
||||
countDown.value.start();
|
||||
};
|
||||
const pause = () => {
|
||||
countDown.value.pause();
|
||||
};
|
||||
const reset = () => {
|
||||
countDown.value.reset();
|
||||
};
|
||||
const onFinish = () => {
|
||||
Toast('倒计时结束');
|
||||
},
|
||||
};
|
||||
|
||||
return {
|
||||
start,
|
||||
pause,
|
||||
reset,
|
||||
onFinish,
|
||||
countDown,
|
||||
};
|
||||
},
|
||||
};
|
||||
```
|
||||
|
||||
Reference in New Issue
Block a user