0

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

1
  • <child-component parentProp="prop" /> so the name of the prop inside the child component will be "parentProp" and contain parent viewmodels "prop" data property. Commented Mar 1, 2018 at 18:32

1 Answer 1

2

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

You need to wrap treeData in quotes:

treenode(:model='treeData')
Sign up to request clarification or add additional context in comments.

1 Comment

I hate replacement syntax like pug, coffeescript, etc... and even more so when it's indentation-based.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.