[英]Vue JS - Add dynamic component based on dropdown selection
I am new to Vue JS and I have below requirement我是 Vue JS 的新手,我有以下要求
Requirement:要求:
I have dropdown with below values我有以下值的下拉列表
On selection of each value, I want to add dropdown component on page, which are already defined.在选择每个值时,我想在页面上添加已经定义的下拉组件。 For example:
例如:
What I have:我有的:
What I tried:我尝试了什么:
Problem:问题:
Note:笔记:
Any help / pointers would be appreciated.任何帮助/指针将不胜感激。 Thanks in advance.
提前致谢。
First you should create Closed and Reviewed components首先,您应该创建 Closed 和 Reviewed 组件
Then, you should have a array of filters:然后,你应该有一个过滤器数组:
data() { return {
filters: [],
} }
When Add filter is clicked you should push corresponding component to filters, something like:单击添加过滤器时,您应该将相应的组件推送到过滤器,例如:
methods: {
addFilter() {
const component = Created /* */;
this.filters.push({
value: null,
component: component
})
}
}
And finally render them in template this way:最后以这种方式在模板中渲染它们:
<div v-for="(filter, index) in filters" :key="index">
<component :is="filter.component" />
</div>
For And/Or
dropdowns, you can use some hacks but I'm not sure how to implement them (you can check if index is zero to only display them between filters)对于
And/Or
下拉菜单,您可以使用一些技巧,但我不确定如何实现它们(您可以检查索引是否为零以仅在过滤器之间显示它们)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.