vant 日歷組件 獲取當前時間


(1)html元素

<span class="f14">{{date_choose}}</span>
  <van-calendar v-model="date_choose_show" :min- date="minDate" @confirm="date_Confirm"></van-calendar>

(2)data數據

// 頁面日歷選擇默認值
date_choose: '',
// 頁面日歷選擇彈出層
date_choose_show: false,
minDate: new Date(2010, 0, 1),

(3)create

created() {
       //初始化日期
       this.getToday();
},

(4)methods

methods: {
      //獲取今天的日期
      getToday: function () {
            let date_choose = new Date();
            this.date_choose = date_choose.getMonth() + 1 + '月' + date_choose.getDate() + '日';
      },
      // 頁面日歷格式化
      formatDate: function (date) {
            return `${date.getMonth() + 1} 月 ${date.getDate()} 日 `;
      },
      // 頁面日歷確認事件
      date_Confirm: function (date) {
           this.date_choose_show = false;
           this.date_choose = this.formatDate(date);
      },
},


免責聲明!

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



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