当前位置:网站首页>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: {
}
}
}
边栏推荐
- 保险公司怎么查高血压?
- Basic teaching of crawler code
- [untitled] 5 self use history
- Jenkins
- Know flex box
- SQL implementation merges multiple rows of records into one row
- Condition annotation in uni-app realizes cross segment compatibility, navigation jump and parameter transfer, component creation and use, and life cycle function
- “我为开源打榜狂”第一周榜单公布,160位开发者上榜
- What are the characteristics and functions of the scientific thinking mode of mechanical view and system view
- mongodb
猜你喜欢
多个全局异常处理类,怎么规定执行顺序
SQL implementation merges multiple rows of records into one row
Pytest -- write and manage test cases
scroll-view指定滚动元素的起始位置
Example of joint use of ros+pytoch (semantic segmentation)
Practical plug-ins in idea
golang操作redis:写入、读取hash类型数据
These two mosquito repellent ingredients are harmful to babies. Families with babies should pay attention to choosing mosquito repellent products
Integration test practice (1) theoretical basis
vmware虚拟机C盘扩容
随机推荐
(翻译)异步编程:Async/Await在ASP.NET中的介绍
Operation principle of lua on C: Foundation
opencv
2021 year end summary
远端rostopic的本地rviz调用及显示
多个全局异常处理类,怎么规定执行顺序
IC_EDA_ALL虚拟机(丰富版):questasim、vivado、vcs、verdi、dc、pt、spyglass、icc2、synplify、INCISIVE、IC617、MMSIM、工艺库
Practical plug-ins in idea
Practice of enterprise ab/testing platform
The essence of interview
Software testing learning - the next day
2022 East China Normal University postgraduate entrance examination machine test questions - detailed solution
【code】if (list != null && list.size() > 0)优化,集合判空实现方式
opencv鼠标键盘事件
Redis command
instanceof
100000 bonus is divided up. Come and meet the "sister who braves the wind and waves" among the winners
【无标题】
数值法求解最优控制问题(一)——梯度法
UNI-APP中条件注释 实现跨段兼容、导航跳转 和 传参、组件创建使用和生命周期函数