element中時間選擇組件,設置default-value無效


1、頁面

2、代碼:

<el-time-picker placeholder="選擇時長"
                            style="width: 100%"
                            v-model="timing"
                            default-value="00:03:00"
            ></el-time-picker>

 

3、分析:

 

 需要將變量解析為 可以被 new Date() 解析的值

 

4、修改

<el-time-picker placeholder="選擇時長"
                            style="width: 100%"
                            v-model="timing"
                            :default-value="new Date(defaultTiming)"
            ></el-time-picker>

  

let t = this.createTimeStr(new Date(), 'ymd') + ' 00:03:00'
this.defaultTiming = new Date(t)

  

 /**
     * 將時間格式化為標准字符串==HH-MM-DD HH:MI:ss
     *
     *
     * */
    createTimeStr (time = new Date(), type = 'ymdhis') {
      let date = new Date(time)
      let Str = ''
      let year = date.getFullYear()
      let month = date.getMonth() + 1
      if (month < 10)month = '0' + month
      let day = date.getDate()
      if (day < 10) day = '0' + day
      let hours = date.getHours()
      if (hours < 10)hours = '0' + hours
      let minutes = date.getMinutes()
      if (minutes < 10)minutes = '0' + minutes
      let Seconds = date.getSeconds()
      if (Seconds < 10)Seconds = '0' + Seconds

      if (type === 'ymdhis') {
        Str = year + '-' +
          month + '-' +
           day + ' ' +
          hours + ':' +
          minutes + ':' +
          Seconds
      } else if (type === 'ymd') {
        Str = year + '-' +
          month + '-' +
          day
      } else if (type === 'his') {
        Str = hours + ':' +
          minutes + ':' +
          Seconds
      }
      return Str
    },

  

5、修改后:

 


免責聲明!

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



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