当前位置:网站首页>Pits encountered in the use of El checkbox group
Pits encountered in the use of El checkbox group
2022-07-03 06:53:00 【God】
What you want to achieve el-checkbox-group multi-select 、 Form validation required
<!-- Error code -->
<el-dialog
title=" Configuration details "
width="395px"
center
>
<el-form
:model="configInfo"
id="form"
ref="form"
:rules="rules"
size="small"
label-position="right"
label-width="120px"
>
<el-form-item label=" Account combination " prop="checkedSubjectIdList">
<el-checkbox-group v-model="configInfo.checkedSubjectIdList">
<el-checkbox v-for="(item,index) in subjectList"
:key="item.subjectId"
:label="item.subjectId"
:class="index%2===1 ? 'cfr':''"
>{
{item.subjectName}}</el-checkbox>
</el-checkbox-group>
</el-form-item>
</el-form>
</el-dialog>
// data structure
data () {
return {
configInfo: {
checkedSubjectIdList: [], // Account combination id
},
subjectList:[
{subjectId:'1',subjectName:'abc'},
{subjectId:'2',subjectName:'cde'}
],
rules: {
checkedSubjectIdList: [{type:'array',required: true, message: ' Mandatory ', trigger: 'change'}],
}
}
}
Error reason , It seems that the data structure is deep ,<el-checkbox-group v-model="configInfo.checkedSubjectIdList"> hold checkedSubjectIdList Take it out alone , Do not nest , To such <el-checkbox-group v-model="checkedSubjectIdList">,:required="true" In order to label There is ‘*’, because checkedSubjectIdList be not in form The binding of configInfo Inside ,rules Also on the checkedSubjectIdList useless , So I have to submit it manually if(this.checkedSubjectIdList.length === 0) Judging empty arrays (( Make do with ......)).
<!-- Corrected code -->
<el-dialog
title=" Configuration details "
width="395px"
center
>
<el-form
:model="configInfo"
id="form"
ref="form"
:rules="rules"
size="small"
label-position="right"
label-width="120px"
>
<el-form-item label=" Account combination " :required="true">
<el-checkbox-group v-model="checkedSubjectIdList">
<el-checkbox v-for="(item,index) in subjectList"
:key="item.subjectId"
:label="item.subjectId"
:class="index%2===1 ? 'cfr':''"
>{
{item.subjectName}}</el-checkbox>
</el-checkbox-group>
</el-form-item>
</el-form>
</el-dialog>
// data structure
data () {
return {
configInfo: {
},
checkedSubjectIdList: [], // Account combination id
subjectList:[
{subjectId:'1',subjectName:'abc'},
{subjectId:'2',subjectName:'cde'}
],
rules: {
}
}
}边栏推荐
- 100000 bonus is divided up. Come and meet the "sister who braves the wind and waves" among the winners
- How matlab modifies default settings
- Scroll view specifies the starting position of the scrolling element
- Hands on redis master-slave replication, sentinel master-slave switching, cluster sharding
- Software testing learning - day one
- Software testing assignment - the next day
- Example of joint use of ros+pytoch (semantic segmentation)
- Understand software testing
- C2338 Cannot format an argument. To make type T formattable provide a formatter<T> specialization:
- 2022-06-23 VGMP-OSPF-域间安全策略-NAT策略(更新中)
猜你喜欢

Practice of enterprise ab/testing platform

如何迁移或复制VMware虚拟机系统

Dbnet: real time scene text detection with differentiable binarization

2022 East China Normal University postgraduate entrance examination machine test questions - detailed solution

Summary of UI module design and practical application of agent mode

SQL implementation merges multiple rows of records into one row

每日刷题记录 (十一)

Selenium - by changing the window size, the width, height and length of different models will be different

Software testing learning - day 3

Personally design a highly concurrent seckill system
随机推荐
“我为开源打榜狂”第一周榜单公布,160位开发者上榜
php artisan
Summary of the design and implementation of the weapon system similar to the paladin of vitality
Climb movie paradise 2021 hot
error C2017: 非法的转义序列
A letter to graduating college students
Thoughts in Starbucks
New knowledge! The virtual machine network card causes your DNS resolution to slow down
Heap sort and priority queue
10000小時定律不會讓你成為編程大師,但至少是個好的起點
Unittest attempt
opencv
Learning notes -- principles and comparison of k-d tree and IKD tree
2022年华东师范大学计科考研复试机试题-详细题解
The essence of interview
Abstract learning
2021 year end summary
Derivation of variance iteration formula
Practical plug-ins in idea
[untitled] 8 simplified address book