vue页面加载时判断当前时间是上午还是下午

<template>
    <div>{{hoursTip}}</div>
</template>
<script>
    export default {
        data() {
            return {
                hoursTip: ''
            }
        },
        created() {
            this.getMycount();
        },
        methods: {
            getMycount () {
                let self = this;
                let date = new Date();

                if (date.getHours() >= 0 && date.getHours() < 12) {

                    self.hoursTip = "上午好"

                } else if (date.getHours() >= 12 && date.getHours() < 18) {

                    self.hoursTip = "下午好"

                } else {

                    self.hoursTip = "晚上好"

                }
            }

        }
    }
</script>
原文地址:https://www.cnblogs.com/wssdx/p/9706003.html