el-date-picker改日期显示方式

效果:

 代码:

<template>
  <div>
    <el-date-picker v-model="selectedDate" type="date" @input="handleDateChange">
      <template #default="{ date }">
        <span>{
   
   { formatDate(date) }}</span>
      </template>
    </el-date-picker>
  </div>
</template>

<script>
export default {
  data() {
    return {
      selectedDate: null
    }
  },
  methods: {
    handleDateChange(date) {
      console.log(date) // 打印选中的日期
    },
    formatDate(date) {
      const year = date.getFullYear()
      const month = date.getMonth() + 1
      const day = date.getDate()
      const weekDay = ['Sunday', 'Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday'][date.getDay()]
      return `${year}-${month}-${day} ${weekDay}`
    }
  }
}
</script>

猜你喜欢

转载自blog.csdn.net/qq_46617584/article/details/133129026