I created a reusable component for Vuetify v-date-picker. I used props to allow setting of value from parent component to child component. Then I created a computed property in the child component for the date ranges to allow changes of props.
The v-date-picker selected the date range on first load but can't make any changes to it.
Template:
<v-date-picker
v-model="dateRange"
color="green"
no-title
range
scrollable
>
<v-spacer></v-spacer>
<v-btn text color="primary" @click="onCancel">
Cancel
</v-btn>
<v-btn text color="primary" @click="onSave">
OK
</v-btn>
</v-date-picker>
Script
props: {
range: {
type: Array,
default: () => {
return [
moment()
.startOf("month")
.format("YYYY-MM-DD"),
moment()
.endOf("month")
.format("YYYY-MM-DD")
];
}
},
},
computed: {
dateRange: {
get() {
return this.range;
},
set(value) {
return value;
}
},
}
But the selection works if I don't use a computed property as v-model from a prop.
Template:
<v-date-picker
v-model="dates"
color="green"
no-title
range
scrollable
>
<v-spacer></v-spacer>
<v-btn text color="primary" @click="onCancel">
Cancel
</v-btn>
<v-btn text color="primary" @click="onSave">
OK
</v-btn>
</v-date-picker>
Script:
data() {
return {
dates: [
moment()
.startOf("month")
.format("YYYY-MM-DD"),
moment()
.endOf("month")
.format("YYYY-MM-DD")
]
}
}