如何在父组件中呈现子组件?

时间:2020-09-25 22:36:27

标签: vue.js

开始情况:

父组件(Parent.vue):

<template>
........
</template>

<script>
export default {
name: 'Parent'
...........
</script

子组件(Child.vue):

<template>
........
</template>

<script>
export default {
name: 'Child'
...........
</script

这3个步骤之后,我可以按顺序在父组件模板中呈现子组件(<Child>标签):

父组件(Parent.vue):

<template>
   <!--step 3:
   use the Child component tag(<Child> custom element) in the parent component template
 --> 
    <Child></Child>
</template>

<script>
//step 1: Import the Child component to the parent component
import Child from "@/path/to/Child.vue";

export default {
    name: 'Parent',
  //Declare the components object 
    components: {
         //step 2: Declare/Register your child components here
             Child // Child is the child component
                }
               }

我的考虑正确吗?

0 个答案:

没有答案
相关问题