简体   繁体   English

从父级传递数据以在组件上呈现,数据传递失败

[英]Passing data from parent to be rendered on component, data passage failure

I am trying to pass a first and last name to a child component to render as a custom element. 我试图将名字和姓氏传递给子组件以呈现为自定义元素。 Should be simple. 应该很简单。 But I am not able to link up my props for some reason. 但是由于某种原因,我无法链接我的道具。 Here is the relevant parent code... 这是相关的父代码...

     <div class="panel-body">
            <full-name  :userData.firstname="firstname"
                        :userData.lastname="lastname"></full-name>
     </div>

<script>
    import toggleSwitch from './components/toggleSwitch.vue';

    export default {
        data () {
            return{
                userData: {
                  firstname: '',
                  lastname: ''
                }
            }
        }, 
        components: {
        'fullName': fullName
        }
    }
</script>

As you can see I call the element and pass it my two data props. 如您所见,我调用了元素并将其传递给我的两个数据道具。 Once there I simply output my data via string interpolation, and... nothing shows. 到达那里后,我仅通过字符串插值输出我的数据,并且...什么也没有显示。 Here is my output component 这是我的输出组件

<template>
  <div>
    <p>{{firstname}} {{lastname}}</p>
  </div>
</template>

<script>

  export default{
    props: ['firstname', 'lastname']
  }

</script>

Am I missing something obvious? 我是否缺少明显的东西? Thanks in advance. 提前致谢。

It should be like this: 应该是这样的:

<full-name  :firstname="userData.firstname" :lastname="userData.lastname"></full-name>

Syntax: 句法:

<comp :prop-name='value'></comp>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM