I am using Vue3 with options API
Given the code posted in StackBlitz here, the default date that initially set is dd.mm.yyyy
. I would like to know how to set the date to that default format. In other words, when the user does specific action, I want to display dd.mm.yyyy
.
For the sake of testing, I tried the following:
methods: {
onDatePickerTimeSeriesAgoToChanged(evt) {
const msg = JSON.stringify({ msg: verboseTag + 'onDatePickerTimeSeriesAgoToChanged():', evt });
console.log(msg);
this.compPropsVModelDatePickerTimeSeriesAgoTo = evt
this.compPropsVModelDatePickerTimeSeriesAgoTo = undefined//<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
},
},
but that did not achieve what I am looking for. How to set the date to dd.mm.yyyy
?
Note:
the question is not about formatting the date. also,
the format of the placeholder does not matter whether it is dd.mm.yyyy or any other thing. the point is how can i display that placeholder? i want to display the placeholder when specific action occurs. is that ever possible please?
in other words, on occurance of a specific condition, i want to change the date-picker from, for example, 01-12-2021 to dd.mm.yyyy
2
Answers
Vue cobtains a so called v-model. It allows for two-way binding. If you edit the input the value changes. If you change the value, the displayed form changes.
Take a look a at the vue-playground:
On load we set a value but when you input anything it also triggers a change. So you could define an event that changes the value and thus the Input.
Alternatively use vue-datepicker, which has a
cleared
-event you could emit when needed.You should use
v-model
here. Refer below, have made the fix.https://stackblitz.com/edit/vue-v7xkzh?file=src%2Fcomponents%2FHelloWorld.vue,src%2FApp.vue
In your template,
In your scripts,
I added the code to let user change the date, show the selected date for 3 seconds, and then reset back to
dd/mm/yyyy
.