created() {
this.myNoonTip();
},
myNoonTip(){
const that = this
const date = new Date()
const hour = date.getHours();
console.log("现在时间是:"+hour+"点!")
if (hour >= 0 && hour < 12) {
that.noonTip = '上午好'
}
else if(hour===12){
that.noonTip = '中午好'
}
else if(hour > 12 && hour < 18) {
that.noonTip = '下午好'
} else {
that.noonTip = '晚上好'
}
}
效果