gpt4 book ai didi

javascript - Vuetify 多个 v-select 所需规则不起作用

转载 作者:行者123 更新时间:2023-12-04 00:53:59 26 4
gpt4 key购买 nike

重现步骤:
如果它的多项选择所需的规则不起作用,如果它不是一个倍数就可以了。
预期行为
规则也适用于多项选择
实际行为
如果它的多重选择规则不起作用
复制代码:

 <div id="app">
<v-app id="inspire">
<v-select
:items="role"
label="Admin level*"
class="mt-3 "
@focus="reset"
item-text="name"
item-value="name"
v-model="roleee"
required
:rules="rules.select"
></v-select>
<v-select
:items="subsidiaries"
label="Subsidiary*"
class="mt-3 "
@focus="reset"
item-text="name"
item-value="name"
v-model="subsidiariesss"
multiple
required
:rules="rules.select"
:menu-props="{ bottom: true, offsetY: true }"
></v-select>
</v-app>
</div>
<script>
new Vue({
el: '#app',
data: {
role:[
{name:'Admin', id:1},
{name: 'SuperAdmin', id:2}
],
subsidiaries: [
{name: "ASdsad", id:1},
{name: "dsd", id:2},
{name: "34", id:3},
{name: "ASvxcdsad", id:4}
],
rules: {
select: [v => !!v || 'Item is required']
}
},
methods: {
reset() {
this.$refs.form.resetValidation();
},
}
})
</script>

最佳答案

您应该添加另一个名为 select2 的规则验证所选项目的长度:

 rules: {
select: [(v) => !!v || "Item is required"],
select2: [(v) => v.length>0 || "Item is required in select 2"],

}
然后将其绑定(bind)到第二个选择,如下所示:
 <v-select
:items="subsidiaries"
label="Subsidiary*"
class="mt-3 "
@focus="reset"
item-text="name"
item-value="name"
v-model="subsidiariesss"
multiple
required
:rules="rules.select2"
:menu-props="{ bottom: true, offsetY: true }"
></v-select>
LIVE DEMO

关于javascript - Vuetify 多个 v-select 所需规则不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/64116145/

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