el-time-picker设置默认赋值时间

2024年08月20日 建站教程

<template>
  <el-time-picker
    v-model="defaultTime"
    value-format="HH:mm:ss"
    @change="changeTime"
    placeholder="选择时间">
  </el-time-picker>
</template>
 
<script>
  export default {
    data() {
      return {
        defaultTime: null
      };
    }
    mounted(){
    this.initTime()
  },
  methods: {
    initTime(){
      let date = new Date()
      this.defaultTime = this.formatTime(date.getHours(), date.getMinutes(), date.getSeconds());
    },
    formatTime(hours, minutes, seconds) {
      return `${this.padStart(hours)}:${this.padStart(minutes)}:${this.padStart(seconds)}`;
    },
    padStart(value) {
      return value.toString().padStart(2, '0');
    },
    changeTime(val){
      console.log(val)
    }
  };
</script>

本文链接:http://so.lmcjl.com/news/11262/

展开阅读全文
相关内容