33 <thead >
44 <tr >
55 <th >Prop</th >
6- <th >Description</th >
7- <th >Message</th >
6+ <th >Value</th >
87 </tr >
98 </thead >
109 <tbody >
1110 <tr >
12- <td >isReadyStatus</td >
13- <td >Timeout status</td >
11+ <td >timerStatus</td >
1412 <td >
15- <span >{{ isReadyStatus }}</span >
13+ <span >{{ timerStatus }}</span >
1614 </td >
1715 </tr >
1816 <tr >
19- <td >timerFnMsg</td >
20- <td >Timer function callback message</td >
17+ <td >timerCallbackMsg</td >
2118 <td >
22- <span >{{ timerFnMsg }}</span >
19+ <span >{{ timerCallbackMsg }}</span >
2320 </td >
2421 </tr >
2522 <tr >
26- <td >
27- <button class =" button is-primary" @click =" resetTimer" >
28- Reset Timer
29- </button >
23+ <td colspan =" 3" >
24+ <button
25+ class =" button is-primary"
26+ @click =" resetTimer"
27+ v-text =" btnResetMsg"
28+ />
3029 <button class =" button is-danger" @click =" cancelTimer" >
3130 Cancel Timer
3231 </button >
3332 </td >
34- <td ></td >
3533 </tr >
3634 </tbody >
3735 </table >
@@ -45,28 +43,40 @@ import { useTimeoutFn } from '../../../vue-use-kit'
4543export default Vue .extend ({
4644 name: ' UseTimeoutFnDemo' ,
4745 setup() {
48- const timerFnMsg = ref (' Timer not completed' )
46+ const timerCallbackMsg = ref (' Timer not completed' )
4947 const timerDuration = 3000
5048 const timerHandler = () => {
51- timerFnMsg .value = ' Timer completed!'
49+ timerCallbackMsg .value = ' Timer completed!'
5250 }
53- const { isReady, cancelTimer, resetTimer } = useTimeoutFn (
51+ const { isReady, isIdle, cancelTimer, resetTimer } = useTimeoutFn (
5452 timerHandler ,
55- timerDuration
53+ timerDuration ,
54+ false
5655 )
5756
58- const isReadyStatus = computed (() => {
57+ const btnResetMsg = computed (() => {
58+ return isIdle .value ? ' Start timer' : ' Reset Timer'
59+ })
60+
61+ const timerStatus = computed (() => {
62+ if (isIdle .value ) return ' Idle'
5963 if (isReady .value === false ) return ' Pending...'
6064 if (isReady .value === null ) return ' Cancelled'
61- return ' Called! '
65+ return ' Completed '
6266 })
6367
6468 watch (isReady , newVal => {
65- if (newVal === false ) timerFnMsg .value = ' Timer not completed'
66- if (newVal === null ) timerFnMsg .value = ' Timer cancelled!'
69+ if (newVal === false ) timerCallbackMsg .value = ' Timer not completed'
70+ if (newVal === null ) timerCallbackMsg .value = ' Timer cancelled!'
6771 })
6872
69- return { timerFnMsg , isReadyStatus , cancelTimer , resetTimer }
73+ return {
74+ timerCallbackMsg ,
75+ btnResetMsg ,
76+ timerStatus ,
77+ cancelTimer ,
78+ resetTimer
79+ }
7080 }
7181})
7282 </script >
0 commit comments