Skip to content

Instantly share code, notes, and snippets.

@Fanna1119
Created July 22, 2020 12:47
Show Gist options
  • Save Fanna1119/a2250b5169f1156cbac9a06ef43d218a to your computer and use it in GitHub Desktop.
Save Fanna1119/a2250b5169f1156cbac9a06ef43d218a to your computer and use it in GitHub Desktop.
vue2 -> vue3 comparison - VUEJS
<template>
<div>
<h1 class="timer">{{toMin}}</h1>
</div>
</template>
<script>
export default {
data() {
return {
difftime: null
};
},
methods: {
updatetick() {
var nowtime = new Date().getTime();
var endDay = new Date().setHours(23, 59, 59);
this.difftime = endDay - nowtime;
}
},
mounted() {
document.title = this.toMin;
this.updatetick();
var vm = this;
setInterval(function() {
vm.updatetick();
}, 60000);
},
computed: {
toMin() {
var minutes = Math.floor(this.difftime / 60000);
return minutes;
}
},
watch: {
difftime() {
document.title = this.toMin;
}
}
};
</script>
<style>
</style>
<template>
<div>
<h1 class="timer">{{state.minutes}}</h1>
</div>
</template>
<script>
import { reactive, onMounted, computed, watchEffect } from "vue";
export default {
setup() {
function updateTick() {
var nowtime = new Date().getTime();
var endDay = new Date().setHours(23, 59, 59);
state.difftime = endDay - nowtime;
}
let state = reactive({
difftime: null,
minutes: computed(() => Math.floor(state.difftime / 60000))
});
watchEffect(() => {
document.title = "1440 | " + state.minutes;
});
onMounted(() => {
updateTick();
setInterval(function() {
updateTick();
}, 60000);
});
return {
state,
updateTick
};
}
};
</script>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment