vue.js - 如何在父组件中使用子组件?
问题描述
我有这种情况:
父组件(Parent.vue):
<template>
........
</template>
<script>
export default {
name: 'Parent'
...........
</script
子组件(Child.vue):
<template>
........
</template>
<script>
export default {
name: 'Child'
...........
</script
为了在父组件的模板中使用子组件(子组件模板)需要做什么?步骤是什么?
解决方案
您可以按照文档中的说明将 Child 称为本地组件。
在 处将组件声明为对象components
。
父.vue:
<template>
<child></child>
</template>
<script>
//Import the Child component to the parent
import Child from "@/path/to/Child.vue";
export default {
name: 'Parent',//Declare the components object
components: {
//Declare your components here
Child //This is the Child component
}
...........
</script>
推荐阅读
- javascript - 带跨度的禁用按钮仍会触发点击功能!角
- python - 将Azure blob读取到pandas df得到以下错误只能将str(不是“tuple”)连接到str?
- javascript - Vue.js如何在更新前显示图像预览
- java - 如何存储到 MongoDB 数据库并使用 Java 从同一个 MongoDB 数据库读取/加载?
- symfony - 如何在 Symfony 表达式语言中将不存在的值评估为 null
- python - 使用 Tensorflow 的 tf.io.gfile.exists 检查文件路径是否存在
- python - 在Python中打印出双引号有空间
- typescript - 打字稿断言条件不缩小已知联合类型
- mysql - 使用 NOLOCK 更新查询
- google-cloud-functions - 带有 Google Cloud Functions 上游请求超时的 ESPv2