Crash course in Vue here so apologies for my lack of knowledge here. I am currently using v-select and running into trouble when creating the v-select element dynamically. I trying to duplicate the element with a new set of data. Not sure what I am doing wrong here.
I would like to be able to click "add input" and a new v-select dropdown is added with the second array list "items2"
Desired output I am looking to accomplish:
Codesanbox: https://codesandbox.io/s/vuetify-ts-forked-99fy7
Vue.js:
<template>
<div>
<div
class="batch-row"
:id="`${index}`"
v-for="(filter, index) in items.slice(0, 1)"
>
<v-select
:items="items"
:id="`${index}`"
item-text="text"
label="Standard"
v-model="filter.value"
>
</v-select>
</div>
<button @click="addInput">Add input</button>
</div>
</template>
<script lang="ts">
import { Component, Vue } from "vue-property-decorator";
@Component
export default class Dropdown extends Vue {
public counter: number = 0;
public items: any[] = [
{ text: "Florida" },
{ text: "Georgia" },
{ text: "Nebraska" },
{ text: "California" },
{ text: "New York" },
];
public items2: any[] = [{ text: "fiz" }, { text: "foo" }, { text: "bar" }];
public addInput(): void {
this.items.push({
id: `${+this.counter}`,
});
}
}
</script>
You can create a variable (
allItems
in this example) that will hold all the array of items. Then, loop through it and renderv-autocomplete
elements per item. Once you click the button, just push theitems2
array toallItems
.Here's a demo at codesandbox: