search

Home  >  Q&A  >  body text

javascript - How to avoid TypeError when passing Object from parent component to child component in vue?

父组件
<father :data="data"></father>
 data() {
      return {
        data: {}
      }
 }

 mounted() {
   this.data = {
     title: '标题'
   }
 }

 子组件
 <son>{{data.title}}<son>
  props: {
  data: Object,
}

报错: title属性 undefined
黄舟黄舟2809 days ago759

reply all(3)I'll reply

  • 巴扎黑

    巴扎黑2017-07-05 10:40:07

    <son v-if="data">{{data.title}}<son>

    reply
    0
  • 世界只因有你

    世界只因有你2017-07-05 10:40:07

    Your initial data should be given the title attribute

    reply
    0
  • 大家讲道理

    大家讲道理2017-07-05 10:40:07

    The writing method is no problem, https://jsfiddle.net/stardew/...

    reply
    0
  • Cancelreply