START

  • 记录一下element-ui 时间组件设置默认值相关做法

代码

<template>
  <div class="#app">
    <el-date-picker
      v-model="value"
      type="datetime"
      format="yyyy-MM-dd HH:mm:ss"
      placeholder="选择时间"
    >
    </el-date-picker>
  </div>
</template>

<script>
export default {
  name: "App",
  data(){
    return{
      value:""
    }
  },
  created(){
    // 1.设置默认值
    this.value=new Date()
    console.log('第一次赋值',this.value)  // Sun Mar 27 2022 00:12:25 GMT+0800 (中国标准时间)

    // 2.虽然展示的格式是标准的`yyyy-MM-dd HH:mm:ss` 但是一开始打印的数据格式不正确

    // 3.记录一下啊,快速处理默认时间的方法
    this.value=new Date(+new Date() + 8 * 3600 * 1000).toISOString().replace(/T/g, ' ').replace(/\.[\d]{3}Z/, '')
    console.log('第二次赋值',this.value)  // 2022-03-27 00:14:17

  }
};
</script>

运行截图

偷懒的番茄

END

  • 比心
Logo

前往低代码交流专区

更多推荐