如何创建可以接收和渲染子组件的父组件?
例如:
<Form>
<Input/>
<Input/>
<Select/>
<Button/>
<Form/>
最佳答案
您可以使用 slots .
Parent.vue
<template>
<form>
<slot/> <!-- The child component will be rendered here -->
</form>
</template>
Child.vue
<template>
<div>
<input/>
<input/>
</div>
</template>
祖 parent .vue
<template>
<div>
<Parent> <!-- Parent component -->
<Child/> <!-- Pass child component to it as slot -->
</Parent>
</div>
</template>
<script>
import Parent from './Parent.vue'
import Child from './Child.vue'
components: {
Parent,
Child
}
</script>
关于javascript - Vue : Create a parent component that can render a child component,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/61027940/