"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