Created
June 10, 2020 00:54
-
-
Save saboyutaka/29e91b378380cf4ac045014f37c1a74b to your computer and use it in GitHub Desktop.
timer.vue
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<script> | |
export default { | |
data() { | |
return { | |
timerId: "", | |
hour: "", | |
minutes: "", | |
second: "", | |
enteredTime: "", | |
}; | |
}, | |
methods: { | |
enter() { | |
// 入室処理 | |
this.$axios | |
.post("/url", { | |
body: "", | |
}) | |
.then(() => { | |
this.enteredTime = "xxxx"; | |
if (this.enteredTimer) { | |
this.startTimer(); | |
} | |
}); | |
}, | |
leave() { | |
// 退室処理 | |
this.$axios | |
.post("/url", { | |
body: "", | |
}) | |
.then(() => { | |
this.enteredTime = null; | |
if (this.timerId) { | |
this.stopTimer(); | |
} | |
}); | |
}, | |
fetchStatus() { | |
// 入室状態確認 | |
this.$axios.get("/url", {}).then(() => { | |
this.enteredTime = "xxxx"; | |
if (this.enteredTimer) { | |
this.startTimer(); | |
} | |
}); | |
}, | |
updateTime() { | |
// enteredTimeと現在時刻の比較 | |
// this.hour = xxx | |
// this.minutes = yyy | |
// this.second = zzz | |
}, | |
startTimer() { | |
this.timerId = setInterval(this.updateTime(), 100); | |
}, | |
stopTimer() { | |
clearInterval(this.timerId); | |
}, | |
}, | |
mounted() { | |
this.fetchStatus(); | |
}, | |
}; | |
</script> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment