1. 程式人生 > 其它 >Vue+elementUI開發問題解決:“TypeError: Cannot read property ‘resetFields‘ of undefined“

Vue+elementUI開發問題解決:“TypeError: Cannot read property ‘resetFields‘ of undefined“

技術標籤:前端頁面vueelementui

本人在開發過程中,因為是引用了相似的頁面部分,所以兩個頁面的el-dialog中:el-form表單ref=“dataAddForm” 都相同

檢查組
檢查項
在測試過程中,開啟某一個dialog是沒有問題的,可以進行驗證。
但是,開啟某一個後,再開啟另外一個,就會報錯了

[Vue warn]: Error in event handler for “click”: “TypeError: Cannot read property ‘resetFields’ of undefined”

TypeError: Cannot read property ‘resetFields’ of undefined

該屬性resetFields 無法定義

在這裡插入圖片描述
所以我的解決方法是:通過判斷是否為空物件,再進行重置

if ( this .$refs["dataAddForm"]!==undefined) {
  	this.$refs["dataAddForm"].resetFields();
}