【发布时间】:2021-08-10 09:29:26
【问题描述】:
我读了一篇文章 "How to dynamically adding different components in Vue".
有一种很好的方法可以将不同的组件绑定到选项卡。
但是我想绑定一个类型/名称组件,它会根据道具而有所不同,而且一个选项卡必须对应于具有相应道具的组件的一个实例。我可以在不同的选项卡中重复使用我的组件吗?
类似:
<template>
<button
v-for="tab in tabs"
v-bind:key="tab.name"
v-bind:class="['tab-button', { active: currentTab === tab }]"
v-on:click="currentTab = tab"
>
{{ tab.name }}
</button>
<component v-bind:is="currentTab.component" :id_1=currentTab.id_1 :id_2=currentTab.id_2></component>
</template>
<script>
import tab-component from "..."
var tabs = [
{
name: "WS1",
component: "tab-component",
uwb_id: "PL_DL_test",
ws_id: "id_Ws_1"
},
{
name: "WS2",
component: "tab-component",
uwb_id: "PL_DL_test",
ws_id: "id_Ws_2"
}
]
export default {
components: {
tab-component
},
data() {
return {
tabs: tabs,
currentTab: tabs[0],
}
}
}
<script>
有可能做这样的事情吗?
感谢回答!!!
【问题讨论】:
标签: javascript vue.js