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)
   }
 })
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章