How to correctly write code with props?


Read docks on vue says that it is not correct to change the values of the props and it gives the GTA V on garage door. When in the beginning he told me, and alert. But the code below it does not swear. In fact I have one component passes the object to another component, and then write the code.

computed: {
 fields () {
 for (var key in {
 if ( ![key]['attr'] )[key]['attr'] = {};
 if ( ![key]['attr']['id'] ){[key]['attr']['id'] = 'Forms_'[key]['name'];

In this case, not so bad that change properties of the parent object, but ideally it would be nice in the future to write more correct code. Tell me how would be correct?
June 10th 19 at 14:51
1 answer
June 10th 19 at 14:53
Need to keep the prop in data () if you plan to change it.
props: {
 value: [String, Number, Object, Array]
data() {
 return {
 mutableValue: this.value

Further mutableValue twist anything. More correct would be to keep the prop value through the watch.
But in this case mutableValue variable will contain an object reference or is there some clever mechanism?
Show if not difficult to watch an example... - Armand_Nader93 commented on June 10th 19 at 14:56
, Look at this component: - pauline.Herman commented on June 10th 19 at 14:59

Find more questions by tags Vue.js