vue頁面加載時判斷當前時間是上午還是下午


<div>{{hoursTip}}</div>

export default{

data(){

  return{

    hoursTip:' ',

  },

}

created{

  this.getMycount();

},

methods:{

  getMycount:function(){

    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="晚上好"

    }

  }

}

}


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM