Vue+elementUI開發問題解決:“TypeError: Cannot read property ‘resetFields‘ of undefined“
阿新 • • 發佈:2021-02-02
本人在開發過程中,因為是引用了相似的頁面部分,所以兩個頁面的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();
}