[Vuejs]-Setting data properties on create to use in prop

1πŸ‘

βœ…

I tested your code and all props are updating normally, however, the reason that isWorking is updating while selectedTaskIdProp does not, seem to be from the id attribute of res[0].task which does not have this attribute. Therefore, you should check if it has this attribute before passing it to the child, through something like:

:selectedTaskIdProp="(isWorking && selectedTask && selectedTask.id) ? selectedTask.id : undefined"

However, the main problem is in the response, so make sure to add the id to it in order to be passed to the child.

EDIT AFTER DEBUGGING THE SANDBOX:

You are setting selectedTaskID in the data of the child directly to the value of the passed prop, which won’t work. The right way is to pass the value in created() of the child component as follows:

data() {
    return {
      selectedTaskIndex: undefined,
      selectedTaskID:null, //update this
      tasks: []
    };
},
created: function() {
    this.tasks = api.getTasks();
    console.log('set this.tasks in TasksLists.vue to')
    console.log(this.tasks);
    this.selectedTaskID = this.selectedTaskIDProp; //update this
}
πŸ‘€Majed Badawi

Leave a comment