V
V
Vlad Tokarev2017-04-04 13:19:33
Vue.js
Vlad Tokarev, 2017-04-04 13:19:33

How to pass object NOT by reference from parent component to child?

Is it possible to somehow pass an object to a child component via props so that changing the object in the child component does not affect the object in the parent, and changing the parent affects the object in the child, i.e. so that the logic of work is the same as with simple variable types?
If not, then there may be other solutions.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
E
Evgeny Kulakov, 2017-04-04
@Vadiok

If I understand you correctly, you can do this:

<parent>
  <child :some_prop="parent_obj"></child>
</parent>

In child element:
<script>
export default {
  props: ['some_prop'],
  data: function() {
    return {
      innerProp: {...this.some_prop}
    }
  }
}
</script>

Those. in the child component, you create a new object based on the incoming one. Then it can be used inside the component as you need.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question