Skip to content

Instantly share code, notes, and snippets.

@saboyutaka
Created June 10, 2020 00:54
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save saboyutaka/29e91b378380cf4ac045014f37c1a74b to your computer and use it in GitHub Desktop.
Save saboyutaka/29e91b378380cf4ac045014f37c1a74b to your computer and use it in GitHub Desktop.
timer.vue
<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