1. 程式人生 > 實用技巧 >vue例項獲取當前系統時間

vue例項獲取當前系統時間

vue例項獲取當前系統時間

效果圖:

程式碼:

<template>
    <div class="home1-3-1 clearfix">
        <span>{{ nowDate }}</span>
        <p> <em>{{ nowYear }}.{{ nowMouth }}</em> <i>{{ nowWeek }}</i> </p>
    </div>
</template>  
<script>
export 
default { data () { return { nowYear: '', nowMouth: '', nowDate: '', nowWeek: '' } }, mouted(){ this.getdate() }, methods:{ getdate() {   const year = new Date().getFullYear()    const mounth
= new Date().getMonth() + 1    const date = new Date().getDate()    const week = new Date().getDay()    if (week === 1) {    this.nowWeek = '星期一'   } else if (week === 2) {   this.nowWeek = '星期二'   } else if (week === 3) {    this.nowWeek = '星期三'    }
else if (week === 4) {    this.nowWeek = '星期四'   } else if (week === 5) {    this.nowWeek = '星期五'   } else if (week === 6) {   this.nowWeek = '星期六'    } else if (week === 27) {    this.nowWeek = '星期日'   }    this.nowYear = year   this.nowMouth = mounth   this.nowDate = date   } } } </script>

css樣式我沒有寫,需要時分秒再通過其對應方法獲取即可,年月日也可以進行拼接