2

Chat

Recently I learned to use vue3+element-plus, and found that Date Picker date picker default-value setting default value does not work, record it

The default values of the examples given in the official website documents are not displayed, as evidenced by the picture:
image.png

Solution

Change the sample code as follows:

  setup() {
  const value1 = ref('')
  const defaultDate = new Date(2010, 9, 1)
  value1.value = defaultDate
  
  const value2 = ref('')
  
  const defaultDateRange = [new Date(2010, 9, 1), new Date(2010, 10, 1)]
  value2.value = defaultDateRange

  return {
    value1,
    value2,
    defaultDate,
    defaultDateRange
  }
},

Effect demonstration

CodePen Home element-plus Date Picker date picker default-value set the default value

Summarize

In fact, it means that setting default-value doesn't work at all, what works is to assign a default value defaultDate to value1.value bound to Date Picker.
Does everyone have a better way? Welcome to discuss
Are the official components still to be improved?


北堂棣
6.6k 声望116 粉丝

2016年应届毕业生。