最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

vue如何動態(tài)獲取當(dāng)前時間

 更新時間:2023年12月02日 14:52:26   作者:性野喜悲  
這篇文章主要介紹了vue如何動態(tài)獲取當(dāng)前時間問題,具有很好的參考價值,希望對大家有所幫助,如有錯誤或未考慮完全的地方,望不吝賜教

vue動態(tài)獲取當(dāng)前時間

獲取當(dāng)前時間:

<template>
  <div id="home">
    <span class="deadline">截止{{ gettime }}</span>
  </div>
</template>
 
<script>
export default {
  name: "Home",
  data() {
    return {
      gettime: "", //當(dāng)前時間
    };
  },
 
  methods: {
    getTime() {
    var _this = this;
      let yy = new Date().getFullYear();
      var mm =
        new Date().getMonth() > 9
          ? new Date().getMonth() + 1
          : new Date().getMonth() == 9
          ? new Date().getMonth() + 1
          : '0' + (new Date().getMonth() + 1);
      var dd = new Date().getDate() < 10 ? '0' + new Date().getDate() : new Date().getDate();
      let hh = new Date().getHours();
      let mf =
        new Date().getMinutes() < 10 ? '0' + new Date().getMinutes() : new Date().getMinutes();
      let ss =
        new Date().getSeconds() < 10 ? '0' + new Date().getSeconds() : new Date().getSeconds();
      _this.gettime = yy + '-' + mm + '-' + dd + ' ' + hh + ':' + mf + ':' + ss;
    },
    currentTime() {
      setInterval(this.getTime, 1000);
    },
   
  },
  mounted() {
    this.currentTime();
  },
};
</script>
 
<style scoped>
</style>?

獲取當(dāng)前日期:

<template>
  <div id="home">
    <span class="deadline">當(dāng)前日期{{ sendTime }}</span>
  </div>
</template>
 
<script>
export default {
  name: "Home",
  data() {
    return {
      sendTime: "", //當(dāng)前時間
    };
  },
  mounted() {
    this.format();
  },
  methods: {
      format() {
                    const nowDate = new Date();
                    const date = {
                        year: nowDate.getFullYear(),
                        month: nowDate.getMonth() + 1,
                        date: nowDate.getDate(),
                    }
                    const newmonth = date.month > 9 ? date.month : '0' + date.month
                    const day = date.date > 9 ? date.date : '0' + date.date
                    this.sendTime = date.year + '.' + newmonth + '.' + day
 
                }, //獲取當(dāng)前時間
   
  },
};
</script>
 
<style scoped>
</style>

vue獲取當(dāng)前時間并時時刷新

頁面顯示

<div><span>{{nowDate}}</span><span class="houertime">{{hourDate}}</span></div>

圖片上傳失敗?。。。?,我是分開年月日和時分秒,給時分秒加樣式

2022/11/24 18:30:20

data中定義變量和定時器

在created中放一個定時器,每秒讀取當(dāng)前時間一次,

在定時器之前先加載,否則會延遲一秒

data(){
    return {
          nowDate: null,
          hourDate: null,
          nowtimer: ''
    }
},

created() {
    this.gettime()  // 如果不先調(diào)用一次的話,頁面顯示一秒后,時間才會顯示
    this.nowtimer = setInterval(this.gettime, 1000);
  },
 methods: {
    gettime() {
        this.nowDate = new Date().toLocaleString('zh', { year: 'numeric', month: 'numeric', day: 'numeric' })
        this.hourDate = new Date().toLocaleString('zh', { hour: 'numeric', minute: 'numeric', second: 'numeric' })
    }
  },

最后進(jìn)行銷毀

beforeDestroy () {
    if (this.nowDate && this.hourDate) {
      clearInterval(this.nowDate, this.hourDate) // 在Vue實例銷毀前,清除定時器
    }
  }

總結(jié)

以上為個人經(jīng)驗,希望能給大家一個參考,也希望大家多多支持腳本之家。

相關(guān)文章

  • Vue3中v-model雙向綁定的避坑指南(2026最新)

    Vue3中v-model雙向綁定的避坑指南(2026最新)

    這篇文章主要為大家詳細(xì)介紹了Vue3中v-model雙向綁定的正確用法和避坑指南,文中的示例代碼講解詳細(xì),感興趣的小伙伴可以跟隨小編一起學(xué)習(xí)一下
    2026-04-04
  • vue項目中監(jiān)聽手機物理返回鍵的實現(xiàn)

    vue項目中監(jiān)聽手機物理返回鍵的實現(xiàn)

    這篇文章主要介紹了vue項目中監(jiān)聽手機物理返回鍵的實現(xiàn),文中通過示例代碼介紹的非常詳細(xì),對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧
    2020-01-01
  • vue3中的抽離封裝方法實現(xiàn)

    vue3中的抽離封裝方法實現(xiàn)

    vue3中的任何一個組合式api都可以單獨抽離出去在另一個文件,最后只需要回歸到setup()中即可,這篇文章主要介紹了vue3的抽離封裝方法,需要的朋友可以參考下
    2022-08-08
  • Vue分別運用class綁定和style綁定通過點擊實現(xiàn)樣式切換

    Vue分別運用class綁定和style綁定通過點擊實現(xiàn)樣式切換

    這篇文章主要為大家介紹了Vue分別運用class綁定和style綁定通過點擊實現(xiàn)樣式切換,有需要的朋友可以借鑒參考下,希望能夠有所幫助,祝大家多多進(jìn)步,早日升職加薪
    2023-07-07
  • 一起來看看Vue的核心原理剖析

    一起來看看Vue的核心原理剖析

    這篇文章主要為大家詳細(xì)介紹了Vue的核心原理,文中示例代碼介紹的非常詳細(xì),具有一定的參考價值,感興趣的小伙伴們可以參考一下,希望能夠給你帶來幫助
    2022-03-03
  • vue中datepicker的使用教程實例代碼詳解

    vue中datepicker的使用教程實例代碼詳解

    這篇文章主要介紹了vue-datepicker的使用,本文通過實例代碼大家介紹的非常詳細(xì),具有一定的參考借鑒價值,需要的朋友可以參考下
    2019-07-07
  • vue3基礎(chǔ)組件開發(fā)detePicker日期選擇組件示例

    vue3基礎(chǔ)組件開發(fā)detePicker日期選擇組件示例

    這篇文章主要為大家介紹了vue3基礎(chǔ)組件開發(fā)-detePicker(日期選擇組件)示例詳解,有需要的朋友可以借鑒參考下,希望能夠有所幫助,祝大家多多進(jìn)步,早日升職加薪
    2023-03-03
  • vue 實現(xiàn)強制類型轉(zhuǎn)換 數(shù)字類型轉(zhuǎn)為字符串

    vue 實現(xiàn)強制類型轉(zhuǎn)換 數(shù)字類型轉(zhuǎn)為字符串

    今天小編就為大家分享一篇vue 實現(xiàn)強制類型轉(zhuǎn)換 數(shù)字類型轉(zhuǎn)為字符串,具有很好的參考價值,希望對大家有所幫助。一起跟隨小編過來看看吧
    2019-11-11
  • vue3實現(xiàn)H5表單驗證組件的示例

    vue3實現(xiàn)H5表單驗證組件的示例

    本文主要介紹了vue3實現(xiàn)H5表單驗證組件的示例,文中通過示例代碼介紹的非常詳細(xì),對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧
    2023-04-04
  • Vue 圖片壓縮并上傳至服務(wù)器功能

    Vue 圖片壓縮并上傳至服務(wù)器功能

    這篇文章主要介紹了Vue 圖片壓縮并上傳至服務(wù)器功能,本文通過實例代碼給大家介紹的非常詳細(xì),具有一定的參考借鑒價值,需要的朋友可以參考下
    2020-01-01

最新評論

交口县| 东阳市| 米易县| 连平县| 池州市| 蒲城县| 绍兴市| 防城港市| 历史| 雷波县| 马公市| 汤原县| 文登市| 蓬安县| 淳化县| 郁南县| 潞西市| 和林格尔县| 定远县| 上饶县| 东兴市| 南康市| 巴东县| 息烽县| 甘洛县| 莆田市| 龙海市| 博乐市| 板桥市| 晋宁县| 青阳县| 织金县| 宜昌市| 寻乌县| 绥阳县| 扎赉特旗| 永春县| 温宿县| 宜川县| 南昌市| 右玉县|