Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
172 views
in Technique[技术] by (71.8m points)

javascript - How do I set nested object entries coming from an api?

I got an object where I keep track of several things that the user can fill out, delete, update, etc.

Now, when 'loading' such a project, I make an api call to my backend using axios to retrieve the specific data to send it back to the client. The api call looks like this:

axios.get(`/api/data/${this.$route.params.dataId}`)
  .then((response) => {

    //Why does this not work?
    this.nestedObject = response.data.object

    //This DOES work... Why?
    this.nestedObject.recipes = response.data.object.recipes
    this.nestedObject.cheffs= response.data.object.cheffs
  })
  .catch((err) => {
    console.log("error retrieving data: ", err);
  });

Whenever I just set this.nestedObject equal to the data that is coming from the server, it does not work. nestedObject is not updated with the new values. But when I set the individual entries in the object equal to the data that is coming from the server, it does work and nestedObject is updated appropriately. Why is that?

question from:https://stackoverflow.com/questions/66049289/how-do-i-set-nested-object-entries-coming-from-an-api

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)
Waitting for answers

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...