【问题标题】:Vuejs - Create a parent componentVuejs - 创建父组件
【发布时间】:2020-01-22 15:57:27
【问题描述】:

是否可以在 Vue 中创建父(包装)组件?我已经看了,我什么都没找到

我想到的是以下内容(v-something 组件来自 vuetify 库):

//cardWrapper.js
<template>
  <v-card>
    <v-row>
      <v-col>
      </v-col>
    </v-row>
  </v-card>
<template>

<script> 
  export default {
    blabla
  } 
</script>

那么这应该以某种方式可用,以便我可以在主文件中

// index.vue
<template>
  <cardWrapper>
    <v-btn>Click Me!</v-btn>
  </cardWrapper>
</template>

我猜这是一个简单的过程,我只是没有正确地用谷歌搜索它。 我唯一能找到的是使用动态组件,但我宁愿不将组件作为属性传递

【问题讨论】:

标签: vue.js


【解决方案1】:

答案如下:

自定义组件

//custom-parent.vue
<template>
  <custom-parent>
    <slot/>
  </custom-parent>
</template>

主文件

//index.vue
<template>
  <custom-parent>
    <a>Hellohello</a>
  </custom-parent>
</template>

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-11-14
    • 2021-06-14
    相关资源
    最近更新 更多