Transfer of the entire data object in the form of props

Is it possible to Vuetransfer the entire object dataas a property?

for instance

Vue.component('comp', {
  props: ['allData'],
  template: '<div>{{allData.msg}}</div>'
})

new Vue({
 el: "#test",
 data: {
   msg: "Hello"
 }
})

In my view :

<div id="test">
  <comp :allData="data"></comp>
</div>
+4
source share
2 answers

The following are possible:

<div id="test">
  <comp :allData="$data"></comp>
</div>

However, a mutation allDatain a component will affect the parent state, since it is an object. See the Vue 1.0 docs warning below:

Please note that if the transmitted transmitted object is an object or an array, it is transmitted by reference. Muting the object or array itself inside the child will affect the parent state, regardless of the type of binding you are using.

Vue 2.0

, JavaScript , , prop , .

+2

$data .

.

+2

Source: https://habr.com/ru/post/1657416/


All Articles