Why can't the data setting field in the component equal to the value in props be set successfully?

the vue document is recommended like this

clipboard.png

clipboard.png

clipboard.png

ask the boss to answer the questions. -sharp-sharp-sharp problem description

the environmental background of the problems and what methods you have tried

related codes

/ / Please paste the code text below (do not replace the code with pictures)

what result do you expect? What is the error message actually seen?

Mar.02,2022

the function of defining local data is props data isolation
since the data is isolated props changes have no effect on the local data, only the initial value
if you want to linkage, watch listen for props fields to update the local data


when the Vue object is created data

So the value in your data is only the default value, you need to use computed or watch to get the value after the runtime update.


Thank you for the questions and answers of the two bosses upstairs. I found the reason, which is similar to what the two bigwigs said, but the point I began to struggle with is not the problem of data linkage update. It's a question of why the initial value is empty.
in the official document, it can be passed because the value of the parent component is that at the beginning, and when the spatio-temporal array of my parent component is obtained through ajax, the updated value is also empty in the data, and the prop will change accordingly, but the data will not, so it is not that there is no this.prop value in the data, but the original value is obtained. Through the test, this is indeed the problem.
Thank you, guys!
I hope it will be helpful to other guys who have doubts about this!

Menu