el-radio-button设置默认选择无效问题

今天使用el-radio-button遇到一个坑,按照官网的方式,如下使用

<el-radio-group v-model="val">
      <el-radio-button label="男" value="1" />
      <el-radio-button label="女" value="2" />
</el-radio-group>

设置了默认值为1,结果没有默认选中,输出val,发现是label的值。

进排查,发现value属性是2.6.0版本才支持的,项目的element plus版本比较旧,不支持。

解决方法,应该采用旧版本写法,如下:

<el-radio-group v-model="val">
      <el-radio-button label="1">男</el-radio-button>
      <el-radio-button label="2">女</el-radio-button>
</el-radio-group>

更新了版本也不保留个旧的文档,唉....,记录一下,做一下备忘。

vue2中:<el-form label-position="right" label-width="80px" size="small" :model="form" style="padding: 0px;" ref="numberValidateForm" :rules="rules"> <el-form-item label="用户名:" prop="name"> <el-input v-model="form.name" style="width: 200px;" name="name"></el-input> </el-form-item> <el-form-item label="用户id:"> <div>{{form.u_id}}</div> </el-form-item> <el-form-item label="手机号:" prop="phone"> <el-input v-model="form.phone" style="width: 250px;" name="phone"></el-input> </el-form-item> <el-form-item label="性别" prop="gender"> <el-radio-group v-model="form.gender"> <el-radio :label="1">男</el-radio> <el-radio :label="2">女</el-radio> <el-radio :label="3">保密</el-radio> </el-radio-group> </el-form-item> <el-form-item label="出生日期" prop="date"> <el-date-picker type="date" :picker-options="pickerOptionsStart" placeholder="选择日期" v-model="form.date" style="width: 200px;"></el-date-picker> </el-form-item> <el-form-item class="e-i-button"> <el-button @click="locationNone">取 消</el-button> <el-button style="margin-left: 200px;" type="primary" @click.stop="areaSubmit('numberValidateForm')">修改</el-button> </el-form-item> </el-form> form: { name: '', date: '', u_id:'', gender: 3, phone: '' }, rules:{ phone: [ { required: false, trigger: 'change' }, { validator: checkMobile, trigger: 'change' }, ], name: [ { required: false, trigger: 'change' }, { validator: checkName, trigger: 'change' }, ] }, async Info(){ if(this.$store.state.user.userInfo){ this.userInfo=await this.$store.state.user.userInfo; if(this.userInfo.birthday!=null){ this.form.date=new Date(this.userInfo.birthday); } this.form.name=this.userInfo.name; this.form.phone=this.userInfo.phone; this.form.u_id=this.userInfo.u_id; if(this.userInfo.gender!=null){ this.form.gender=this.userInfo.gender; } this.avatarUrl='http://127.0.0.1:9090'+this.userInfo.picture.slice(8) return true; } },date可以输入,在注释掉赋值语句后可以均可正常输入,
03-27
父页面<el-radio v-model="item.likeBad" label="0" class="likeBtn" :class="`likeBtn-${item.funcId}-${user.billId}`" @click.native="clickBtn('likeBtn', item,'0')"><span style="margin-left: 17px;line-height: 22px;">好评</span></el-radio> <el-radio v-model="item.likeBad" label="1" class="normalBtn" :class="`normalBtn-${item.funcId}-${user.billId}`" @click.native.prevent="clickBtn('normalBtn', item,'1')"><span style="margin-left: 17px;line-height: 22px;">一般</span> </el-radio> <el-radio v-model="item.likeBad" label="2" class="badBtn" :class="`badBtn-${item.funcId}-${user.billId}`" @click.native.prevent="clickBtn('badBtn', item,'2')"><span style="margin-left: 17px;line-height: 22px;">差评</span> </el-radio> <!-- 公共Dialog组件 --> <eval-dialog :visible.sync="dialogVisible[item.funcId]" :item="item" :good-reason="goodReason" :bad-reason="badReason" :submit-loading="submitLoading" @eval-change="handleEvalChange" @submit="submitBadReason" />子页面<!-- components/EvalDialog.vue --> <template> <el-dialog :visible="visible" @close="handleClose" custom-class="badBtnDetail"> <div style="border-bottom: 1px dashed #D9D9D9; height: 36px;"> <el-radio-group v-model="innerItem.likeBad" @change="handleEvalChange"> <el-radio label="0" class="likeBtn"> <span style="margin-left: 17px; line-height: 22px;">好评</span> </el-radio> <el-radio label="1" class="normalBtn"> <span style="margin-left: 17px; line-height: 22px;">一般</span> </el-radio> <el-radio label="2" class="badBtn"> <span style="margin-left: 17px; line-height: 22px;">差评</span> </el-radio> </el-radio-group> </div> <!-- 动态原因选择 --> <div v-if="innerItem.likeBad !== '1'"> <!-- 好评原因 --> <el-checkbox-group v-model="innerItem.goodReasonList" v-if="innerItem.likeBad === '0'" > <el-checkbox v-for="(reason, index) in goodReason" :key="'good-'+index" :label="reason.para1" class="badReasonItem" /> </el-checkbox-group> <!-- 差评原因 --> <el-checkbox-group v-model="innerItem.badReasonList" v-if="innerItem.likeBad === '2'" > <el-checkbox v-for="(reason, index) in badReason" :key="'bad-'+index" :label="reason.para1" class="badReasonItem" /> </el-checkbox-group> <!-- 其他原因输入框 --> <el-input v-if="showOtherInput" type="textarea" :rows="2" placeholder="请输入其他原因" v-model="innerItem.badReasonTxt" style="margin-top: 10px;" /> </div> <span slot="footer" class="dialog-footer"> <el-button type="primary" @click="handleSubmit" v-loading="submitLoading">提 交</el-button> </span> </el-dialog> </template> <script> import { Button, Dialog, Input, Radio, RadioGroup, Checkbox, CheckboxGroup } from 'element-ui'; export default { name: 'EvalDialog', props: { visible: Boolean, item: Object, goodReason: Array, badReason: Array, submitLoading: Boolean }, components: { [Button.name]: Button, [Dialog.name]: Dialog, [Input.name]: Input, [Radio.name]: Radio, [RadioGroup.name]: RadioGroup, [Checkbox.name]: Checkbox, [CheckboxGroup.name]: CheckboxGroup, }, data() { return { innerVisible: this.visible, // 用内部变量存储 visible innerItem: { ...this.item } }; }, computed: { showOtherInput() { return this.innerItem.likeBad === '0' && this.innerItem.goodReasonList.includes('其他') || this.innerItem.likeBad === '2' && this.innerItem.badReasonList.includes('其他'); } }, methods: { handleEvalChange() { this.$emit('eval-change', this.innerItem); }, handleSubmit() { this.$emit('submit', this.innerItem); }, handleClose() { this.innerItem = { ...this.item }; // 重置内部状态 this.innerItem['visible'] = false; console.log('触发 input 事件'); this.innerVisible = false; // 修改内部变量而非 prop } }, watch: { visible(newVal) { this.innerVisible = newVal; // 父组件更新时同步到内部变量 }, innerVisible(newVal) { this.$emit('update:visible', newVal); // 内部变量变化时通知父组件 } } }; </script> 为什么子页面点关闭,关不了弹窗,为什么父页面默认选中单选时,再点击默认的单选不能弹窗,如何优化修改
07-10
<template> <div> <h3>课程信息</h3> <el-form ref="form" :model="form" label-width="80px"> <el-form-item label=""> 课程名称 <el-input v-model="form.courseName" style="width: 200px"></el-input> 课程时间 <el-date-picker v-model="startEndTime" type="datetimerange" range-separator="至" start-placeholder="开始日期" end-placeholder="结束日期" > </el-date-picker> <el-button style="background-color: red; color: aliceblue" >搜索</el-button > </el-form-item> </el-form> <div id="box"> <div> <el-radio-group v-model="form.status" style="width: 300px; float: left"> <el-radio-button label="1">已预约</el-radio-button> <el-radio-button label="2">已结束</el-radio-button> </el-radio-group> </div> <ul> <li v-for="v in list" :key="v.id"> <div> <el-button @click="toCourseDetail(v.id)"> <img v-bind:src="v.pic" alt="" /> <h4>{{ v.courseName }}</h4> <p style="white-space: pre-wrap">{{ v.introduce }}</p> </el-button> </div> </li> </ul> </div> <div> <el-dialog title="提示" :visible.sync="centerDialogVisible" width="30%" center > <span slot="footer" class="dialog-footer"> <el-button @click="centerDialogVisible = false">取 消</el-button> <el-button type="primary" @click="courseDetail">确 定</el-button> </span> </el-dialog> </div> <!-- 分页组件 --> <el-pagination background layout="prev, pager, next" :total="total" :page-size="pageSize" :current-page="pageNum" @current-change="handlePageChange" ></el-pagination> </div> </template> <script> import { findAllUserCourse } from '@/api/user'; export default { data() { return { centerDialogVisible:false, startEndTime: "", pageSize:6, pageNum:1, total:0, form: { startTime: "", endTime: "", page: "", size: "", resname: "", userId: "", }, list: [ { value: "0", id: "", pic: "", courseName: "", introduce: "", }, ], }; }, created() { this.findAllUserCourse(); }, methods: { findAllUserCourse(){ this.userId=localStorage.getItem("userId") this.form.page = this.pageNum; this.form.size = this.pageSize; this.form.resname = this.form.courseName; this.form.startTime = this.formatDate(this.startEndTime[0]); this.form.endTime = this.formatDate(this.startEndTime[1]); findAllUserCourse(this.form).then((resp)=>{ this.list = resp.data.data.courses.list; console.log(this.list); this.total = resp.data.data.courses.total; this.form.startTime = ""; this.form.endTime = ""; }) }, toCourseDetail(id) { this.centerDialogVisible=true this.courseDetail(id) }, courseDetail(){ }, handlePageChange(page) { this.pageNum = page; this.findCourseAll(); }, formatDate(date) { if (!date) return ""; const year = date.getFullYear(); const month = (date.getMonth() + 1).toString().padStart(2, "0"); const day = date.getDate().toString().padStart(2, "0"); const hours = date.getHours().toString().padStart(2, "0"); const minutes = date.getMinutes().toString().padStart(2, "0"); const seconds = date.getSeconds().toString().padStart(2, "0"); return `${year}-${month}-${day} ${hours}:${minutes}:${seconds}`; }, }, }; </script> <style scoped> #box ul { display: flex; flex-wrap: wrap; position: absolute; top: 220px; } #box li { padding: 3px; list-style: none; margin-right: 15px; border: 1px solid #eee; } #box img { width: 200px; height: 150px; } </style>报错UserCourseView.vue:110 [Vue warn]: Error in render: "TypeError: Cannot read properties of null (reading 'id')"
最新发布
09-04
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值