A
A
Andrey Suha2019-11-11 16:41:31
Vue.js
Andrey Suha, 2019-11-11 16:41:31

Why is the computed property not overridden?

There is a computed property

formattedDate() {
            let date = this.date ? this.date : this.value;
            return date ? moment(date).format(this.getFormat) : date;
        }

date is a property in data, when it changes, formattedDate is not reset, although the date property itself changes
https://codesandbox.io/s/vue-template-mqyo8
when you select a date the second time, the property is not reset. The property itself in components/date-picker/index.vue
UPD if you close/open the calendar (double click on the input), then the date can be selected again, but again only once

Answer the question

In order to leave comments, you need to log in

3 answer(s)
O
Oleg, 2019-11-12
@andreysuha

In fact, it is very strange that it does not work either when moving from a computed property to a method, or when using this.$set. And forceUpdate did not help.
The only way to fix it is to create a formattedDate reactive prop and put the formatted date there in the setSelectedDate method.
Something like this

S
Shtucer, 2019-11-11
@Shtucer

From the word "shit"?

A
Andrey Ololoshchenko, 2019-11-12
@veremii

Everything is very interesting. I dare to suggest that you store an object in the this.date variable, thereby you return a link! On the this.date object is visible.
Try writing something like let date = this.date ? JSON.parse(JSON.stringify(this.date)) : ...
If it works as expected, then you have an architectural error and need to think about it.
Also computed properties are cached, don't forget that.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question