При изменении значения элемента INPUT установщик не вызывается, когда v-модель элемента ссылается на объект.С помощью метода click обе версии возраста изменяются, и метод установки вызывается как для простой переменной, так и для объекта.Если я изменю возраст через элемент input, то будет вызван только вычислитель простой переменной.Чего мне не хватает?
https://jsfiddle.net/sday/eywraw8t/411036/
<input type="text" v-model.number="age">
<input type="text" v-model.number="person.age">
new Vue({
el: "#app",
data: {
aperson:{age:25},
iAge:25,
text:""
},
computed: {
age : {
get () {
return this.iAge },
set (value) {
debug(this,"update detected through simple age variable: ");
this.iAge=value;
},
},
person : {
get () {
return this.aperson },
set (value) { // <--- doesn't get called when changing through inputbox
debug(this,"update detected through person object: ");
},
}
},
methods: {
click: function (e) {
this.iAge++;
// this.person.age++; // <--- this also works to increment
this.$set(this.person, "age", this.person.age+1); // <-- thought maybe I had to do this for setter to be called during a change event
},
}
})