I have one file vue component with one property 'todo-item' with such structure
{
id:1,
text:'Buy tickets',
isDone: false,
person:'Boss',
location:'Boryspil',
childTask:null,
},
And I have computed properties:
computed:{
hasLocation(){
return this.todoItem.location;
},
hasPerson(){
return this.todoItem.person;
},
hasChildTask(){
return this.todoItem.childTask;
},
hasParentTask(){
return true;
},
}
And I want to make all of object properties reactive, but when I change properties in method:
deletePerson(){
this.$set(this.todoItem, 'person', null);
console.log(this.hasPerson);
console.log(this.todoItem.person);
},
todoItem.person is still not reactive, this.hasPerson have old value, and this.todoItemPerson shows null value.
I tried to make them reactive on created
method, but it's still not reactive.
This is by component whole js code, without template and css for short:
<script>
import HoveredChip from "@/components/HoveredChip";
import {mapMutations} from 'vuex';
export default {
name: "TodoItem",
components: {HoveredChip},
props:['todo-item'],
data() {
return{
isActive : true,
}
},
computed:{
hasLocation(){
return this.todoItem.location;
},
hasPerson(){
return this.todoItem.person;
},
hasChildTask(){
return this.todoItem.childTask;
},
hasParentTask(){
return true;
},
people(){
return [
"dad",
"Ann",
"boss",
"prostitute"
]
},
places(){
return []
}
},
methods:{
...mapMutations(['addPersonMutation'],{
}),
moveToPerson(){
},
moveToLocation(){
},
moveToPatentTask(){
},
addLocation(){
},
addPerson(val){
this.addPersonMutation(val);
this.$set(this.todoItem,'person',val);
console.log(this.hasPerson);
console.log(this.todoItem.person);
},
addChildTask(){
},
deletePerson(){
this.$set(this.todoItem, 'person', null);
console.log(this.hasPerson);
console.log(this.todoItem.person);
},
deleteLocation(){
},
deleteChildTask(){
},
editLocation(){
},
savePerson(){
},
editChildTask(){
}
},
created(){
// this.$set(this.todoItem, 'person', 'undefined');
// this.$set(this.todoItem, 'location', '????');
// this.$set(this.todoItem, 'isDone', "....");
}
}
</script>