vue+element 表单BUG记录

介绍:

复现:一般都是表单中,二级联动或者三级联动,使用change方法改变form:{ name:’’ }中的属性;
1.视图不更新
2.el-select下拉全选;

针对问题一解决方法:

//使用$set
this.$set(this.newTeam,"provinceId", '')
this.$set(this.newTeam,"province", '')

//下面这个会不生效,导致表单异常,更新数据滞后,需手动触发更新
// this.newTeam.provinceId = ''
// this.newTeam.province = ''

针对问题一解决方法:

//起初我以为是问题一,后来发现不是因为视图不更新
//这个问题我也遇到过,没当回事,因为最开始我特别喜欢使用map方法
//当我现在喜欢使用find,findIndex等方法后发现此问题

//此方法会导致下拉选项全部选中
// let current = this.doctorTeamOptions.find(res => res.id = val)
// this.$set(this.form,"doctorGroupName", current.name)

//分析:数组的变异方法例如find,findIndex等会返回新数据,change中使用导致数据源改变。

//使用map解决
 this.doctorTeamOptions.map((item)=>{
   if(item.id == val){
     this.$set(this.form,"doctorGroupName", item.name)
   }
 })
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章