"TypeError: Cannot read property 'resetFields' of undefined"


 一個Element 組件庫下 Dialog 窗口的 form 組件的 close 事件,觸發了 formRef 的 resetFields 方法,報錯如下:

[Vue warn]: Error in v-on handler: "TypeError: Cannot read property 'resetFields' of undefined"

found in

---> <ElDialog> at packages/dialog/src/component.vue
       <Anonymous>
         <ElMain> at packages/main/src/main.vue
           <ElContainer> at packages/container/src/main.vue... (1 recursive calls)
             <Home> at src/components/home.vue
               <App> at src/App.vue
                 <Root>

TypeError: Cannot read property 'resetFields' of undefined
at VueComponent.addClose (params.vue?f2b2:258)
at invokeWithErrorHandling (vue.runtime.esm.js?2b0e:1854)
at VueComponent.invoker (vue.runtime.esm.js?2b0e:2179)
at invokeWithErrorHandling (vue.runtime.esm.js?2b0e:1854)
at VueComponent.Vue.$emit (vue.runtime.esm.js?2b0e:3888)
at VueComponent.visible (dialog.js?df33:480)
at Watcher.run (vue.runtime.esm.js?2b0e:4568)
at flushSchedulerQueue (vue.runtime.esm.js?2b0e:4310)
at Array.eval (vue.runtime.esm.js?2b0e:1980)
at flushCallbacks (vue.runtime.esm.js?2b0e:1906)

網上說 這個錯誤是因為你的dom元素還沒有加載完,你就想使用resetFields置空。也就是你寫的this.$refs['addForm'].resetFields();這個里面的addForm還沒有加載出來呢。

但是項目中 formRef 對應的 form 所綁定的數據 ,本來就是前期通過axios查詢到的數據做的 :model 綁定,應該不會存在 resetFields 方法觸發的時候 對應的 DOM 元素還沒加載完的情況,具體原因未知,待確認

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM