gpt4 book ai didi

javascript - Vuetify组合框多次添加选项?

转载 作者:行者123 更新时间:2023-12-01 15:21:44 31 4
gpt4 key购买 nike

我正在使用 vuetify 框架,我遇到了这个问题,我不确定如何从列表中多次添加一个项目。我有一个下拉列表,我想添加选项 foo或任何选项多次选择。这是演示的链接codepen .

所以现在如果我选择 foo 或任何其他选项,然后从下拉列表中再次选择它,它就会消失,而是我想要另一个具有相同选项的芯片
加进去了吗?

new Vue({
el: '#app',
data() {
return {
items: [{
text: 'Foo',
value: 'foo'
},
{
text: 'Bar',
value: 'bar'
},
{
text: 'biz',
value: 'buzz'
},
{
text: 'buzz',
value: 'buzz'
}
],
}
}
})
<link href="https://cdn.jsdelivr.net/npm/vuetify@1.5.14/dist/vuetify.min.css" rel="stylesheet" />
<script src="https://cdn.jsdelivr.net/npm/vuetify@1.5.14/dist/vuetify.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/vue/2.5.17/vue.js"></script>
<div id="app">
<v-app id="inspire">
<v-container>
<v-combobox :items="items" label="Add Multiple Chips" multiple small-chips solo deletable-chips>
<template v-slot:item="{ index, item }">
<v-list-tile-content>
{{item.text}}
</v-list-tile-content>
</template>
<template v-slot:selection="{ index, item }">
<v-chip close dark color="info">
{{ item.text }}
</v-chip>
</template>
</v-combobox>
</v-container>
</v-app>
</div>


如果有人对如何实现这一目标有任何线索。将不胜感激。谢谢

最佳答案

几个小调整,

  • 放一个.stop在项目上单击以防止 Vuetify 在您的处理程序后处理
  • 告诉组合框对 :value 使用 arr
  • 将删除点击处理程序添加到 v-chip和相应的方法(注意这适用于 Vuetify 2.1.0,但不适用于 Codepen 上使用的 Vuetify 1.5.14。如果您不需要该特定版本,请安装最新版本。

  • Codepen Vuetify v1.5.14

    CodeSandbox Vuetify v2.1.0

    <template>
    <div id="app">
    <v-app id="inspire">
    <v-container>
    <v-combobox
    :items="items"
    label="Add Multiple Chips"
    multiple
    small-chips
    solo
    deletable-chips
    :value="arr"
    >
    <template v-slot:item="{ index, item }">
    <v-list-tile-content @click.stop="multipleSelection(item)">{{item.text}}</v-list-tile-content>
    </template>
    <template v-slot:selection="{ index, item }">
    <v-chip close dark color="info"
    @click:close="deleteChip(item)" >{{ item.text }}</v-chip>
    </template>
    </v-combobox>
    </v-container>
    </v-app>
    </div>
    </template>

    <script>
    export default {
    name: "playground",
    data: () => ({
    arr: [],
    items: [
    {
    text: "Foo",
    value: "foo"
    },
    {
    text: "Bar",
    value: "bar"
    },
    {
    text: "biz",
    value: "buzz"
    },
    {
    text: "buzz",
    value: "buzz"
    }
    ]
    }),
    methods: {
    multipleSelection(item) {
    this.arr.push({...item});
    console.log(this.arr);
    },
    deleteChip(item) {
    this.arr = this.arr.filter(x => x !== item);
    console.log(this.arr);
    }
    }
    };
    </script>

    关于javascript - Vuetify组合框多次添加选项?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60118913/

    31 4 0
    Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
    广告合作:1813099741@qq.com 6ren.com