I want to make the dynamic content inside the Collapse button/element/dropdown. Because I will reuse it a lot. So how can I pass components inside the Collapse? For example there is some DataTable in the Collapse where I can press "+" button and another collapse would appear(I already made it) and there is another content, and I want to use those collapses, and inside of it wouldn't be a table, but for example a form. I want to Optimize it and use it for future collapses with different content.
I am using VueJS 2, BootstrapVue
这是我的折叠节.vue
<template>
<div class="accordion" role="tablist">
<b-button block v-b-toggle.accordion-1 class="collapse-btn" align-h="between">
{{ selectText }}
<b-icon :icon="visible ? 'caret-down' : 'caret-up'" class="icon"></b-icon>
</b-button>
<b-card no-body class="mb-1">
<b-collapse id="accordion-1" v-model="visible" accordion="my-accordion" role="tabpanel">
<b-card-body>
<DataTable :labels="labels" :data="data" :showAdd="true" @add-item="addItem"/>
</b-card-body>
</b-collapse>
</b-card>
//below is dynamic collapse when Click on "+" button
<div v-for="(item, index) in items" :key="index">
<b-button block v-b-toggle="'accordion-' + (index + 2)" class="collapse-btn">
{{ item.name }}
<b-icon :icon="visible ? 'caret-down' : 'caret-up'" class="icon"></b-icon>
</b-button>
<b-card no-body class="mb-1">
<b-collapse :id="'accordion-' + (index + 2)" accordion="my-accordion" role="tabpanel">
<b-card-body>
some content
</b-card-body>
</b-collapse>
</b-card>
</div>
</div>
</template>
<script>
export default {
name: "CollapseButton",
components: {DataTable},
props: {
selectText: {
type: String,
default: () => "Select",
},
},
data() {
return {
items: [],
visible: false,
}
},
}
</script>
NewForm.vue //is just an example when I call/use it collapse component(only template, cuz script is
<template>
<CollapseSection select-text="Collapse ">
</CollapseSection>
</template>
<script>
export default {
name: "NewForm",
components: {CollapseSection},
}
</script>
如何对其进行优化并使方法/操作正常工作(因为在每个折叠中,数据和操作/方法应该相互关联