Answer the question
In order to leave comments, you need to log in
How to add computed to v-model?
Here is a period selection.
Click on it and the date should be filled in the datepicker
<input v-model="selectedPeriod"
:id="period.id" :value="period.id"
type="radio" name="period"
class="policy-form__label-radio" />
<el-date-picker
v-model="dateStart"
type="date"
:clearable="false"
placeholder="Выберите дату">
</el-date-picker>
data: () => ({
periodStart: new Date(),
periodEnd: new Date(),
selectedFilter: "all",
selectedPeriod: "today"
}),
dateStart() {
return moment().subtract(1, this.selectedPeriod).toDate()
}
Computed property "dateStart" was assigned to but it has no setter
Answer the question
In order to leave comments, you need to log in
For computed properties, you can do (and you need to in this situation) and setters:
dateStart: {
get() {
return moment().subtract(1, this.selectedPeriod).toDate();
},
set(value) {
// ну, тут вам виднее, какой должен код быть
},
},
Well, as if they hint quite clearly that there is an assignment to dateStart, but the setter is undefined, there should be something like:
dateStart: {
get: function () {
return moment().subtract(1, this.selectedPeriod).toDate()
},
set: function (v) {
// set here
}
}
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question