亚洲乱码中文字幕综合,中国熟女仑乱hd,亚洲精品乱拍国产一区二区三区,一本大道卡一卡二卡三乱码全集资源,又粗又黄又硬又爽的免费视频

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

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

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

獲取當前時間:

<template>
  <div id="home">
    <span class="deadline">截止{{ gettime }}</span>
  </div>
</template>
 
<script>
export default {
  name: "Home",
  data() {
    return {
      gettime: "", //當前時間
    };
  },
 
  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>?

獲取當前日期:

<template>
  <div id="home">
    <span class="deadline">當前日期{{ sendTime }}</span>
  </div>
</template>
 
<script>
export default {
  name: "Home",
  data() {
    return {
      sendTime: "", //當前時間
    };
  },
  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
 
                }, //獲取當前時間
   
  },
};
</script>
 
<style scoped>
</style>

vue獲取當前時間并時時刷新

頁面顯示

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

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

2022/11/24 18:30:20

data中定義變量和定時器

在created中放一個定時器,每秒讀取當前時間一次,

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

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' })
    }
  },

最后進行銷毀

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

總結(jié)

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

相關文章

  • vue 百度地圖(vue-baidu-map)繪制方向箭頭折線實例代碼詳解

    vue 百度地圖(vue-baidu-map)繪制方向箭頭折線實例代碼詳解

    這篇文章主要介紹了vue 百度地圖(vue-baidu-map)繪制方向箭頭折線,本文通過實例代碼給大家介紹的非常詳細,對大家的學習或工作具有一定的參考借鑒價值,需要的朋友可以參考下
    2020-04-04
  • 關于Vue?ui?的沒反應、報錯問題解決總結(jié)

    關于Vue?ui?的沒反應、報錯問題解決總結(jié)

    這篇文章主要介紹了關于Vue?ui?的沒反應、報錯問題解決總結(jié),具有很好的參考價值,希望對大家有所幫助。如有錯誤或未考慮完全的地方,望不吝賜教
    2022-09-09
  • Vue3.0手寫輪播圖效果

    Vue3.0手寫輪播圖效果

    這篇文章主要為大家詳細介紹了Vue3.0手寫輪播圖效果,文中示例代碼介紹的非常詳細,具有一定的參考價值,感興趣的小伙伴們可以參考一下
    2021-10-10
  • Vue的Class與Style綁定的方法

    Vue的Class與Style綁定的方法

    本篇文章主要介紹了Vue的Class與Style綁定的方法,小編覺得挺不錯的,現(xiàn)在分享給大家,也給大家做個參考。一起跟隨小編過來看看吧
    2017-09-09
  • vue下載excel的實現(xiàn)代碼后臺用post方法

    vue下載excel的實現(xiàn)代碼后臺用post方法

    這篇文章主要介紹了vue下載excel的實現(xiàn)代碼,后臺用post方法,本文通過實例代碼給大家介紹的非常詳細,具有一定的參考借鑒價值 ,需要的朋友可以參考下
    2019-05-05
  • Vue組件封裝之input輸入框?qū)崙?zhàn)記錄

    Vue組件封裝之input輸入框?qū)崙?zhàn)記錄

    在vue中會將常用的組件進行封裝,下面這篇文章主要給大家介紹了關于Vue組件封裝之input輸入框的相關資料,文中通過示例代碼介紹的非常詳細,需要的朋友可以參考下
    2022-10-10
  • vue背景圖片路徑問題及解決

    vue背景圖片路徑問題及解決

    這篇文章主要介紹了vue背景圖片路徑問題及解決方案,具有很好的參考價值,希望對大家有所幫助。如有錯誤或未考慮完全的地方,望不吝賜教
    2022-07-07
  • 一文帶你上手Vue新的狀態(tài)管理Pinia

    一文帶你上手Vue新的狀態(tài)管理Pinia

    Vuex 作為一個老牌 Vue 狀態(tài)管理庫,大家都很熟悉了,Pinia 是 Vue.js 團隊成員專門為 Vue 開發(fā)的一個全新的狀態(tài)管理庫,本文就來講講它的具體使用吧
    2023-04-04
  • 組件庫中使用 vue-i18n 國際化的案例詳解

    組件庫中使用 vue-i18n 國際化的案例詳解

    這篇文章主要介紹了組件庫中使用 vue-i18n 國際化,本文通過實例代碼給大家介紹的非常詳細,對大家的學習或工作具有一定的參考借鑒價值,需要的朋友可以參考下
    2023-04-04
  • vue中nextTick用法實例

    vue中nextTick用法實例

    在本篇文章里小編給大家整理了關于vue中nextTick用法實例以及相關代碼內(nèi)容,需要的朋友們可以參考下。
    2019-09-09

最新評論