user345234674567
user345234674567

Reputation: 321

vue.js pass Object to component

I have 2 vue components, I would like to pass an object from the parent to the child component.

componentA

<template lang="pug">
  .wrapper
    treenode(:model=treeData)
    div -----------------
    div {{treeData}}

</template>

<script>
  import treenode from './treenode.vue'

  export default {
    props : ['items']
  , components : { treenode : treenode }
  , created(){
        this.treeData = {name:"test"}
    }
</script>

comp treenode

 export default {
    props : {
      model: {
        type : Object
      , default : function(){ return { name : "default" } }
      }
    }

model in comp treenode is always the default value

Upvotes: 0

Views: 747

Answers (1)

thanksd
thanksd

Reputation: 55644

You aren't passing the prop value in the child component tag correctly.

You need to wrap treeData in quotes:

treenode(:model='treeData')

Upvotes: 2

Related Questions