I have a Nuxtjs/Vuejs application that contains the input field of type datetime-local
. For this field, I would like to add the current DateTime as the default value. I have done similar things in AngularJS
but for some reason, it is not working in Vuejs.
Following is the field:
<input v-model="formData.eventtimeSpecific" type="datetime-local" class="form-control" title="Set Specific Event Time">
Following is the JS function for it:
export default {
data(){
return {
formData:{
eventtimeSpecific: new Date(),
}
}
},
mounted () {
const today = new Date()
this.formData.eventtimeSpecific.setHours(today.getHours(), today.getMinutes(), 0, 0)
},
}
Similar approach when I tried in Angularjs it was working:
$scope.formdata.eventtimeSpecific = new Date();
var h = $scope.formdata.eventtimeSpecific.getHours();
var m = $scope.formdata.eventtimeSpecific.getMinutes();
$scope.formdata.eventtimeSpecific.setHours(h,m,0,0);
Can someone please assist me in how to set the current DateTime value as the default value for datetime-local
type input field?
Current behavior:
Expected behavior: