简体   繁体   English

Vue.js:“TypeError:无法读取未定义的属性(读取'$refs)'”

[英]Vue.js: "TypeError: Cannot read properties of undefined (reading '$refs)'"

We are triggering methods from a parent component in a child component like so:我们在子组件中从父组件触发方法,如下所示:

await this.$refs.patientinputmask.$refs.patientpersonaldata.ChangePersonalData();
await this.$refs.patientinputmask.$refs.patientaddressdata.SavePersonalAddressObject();
await this.$refs.patientinputmask.$refs.patientbankaccountdata.SavePersonalBankAccountObject();
await this.$refs.patientinputmask.$refs.patientrelatedcontacts.SaveRelatedContactObject();
if (this.invoiceHN == true) {
          await this.$refs.patientinputmask.$refs.invoicedata.$refs.invoiceHN.$refs.invoiceKasseHeaderHN.SavePatientDataForInvoice();
          await this.$refs.patientinputmask.$refs.invoicedata.$refs.invoiceHN.$refs.invoicingTemplateHN.SavePatientTemplateConfigDTO();
        }

From time to time an error occurs: [Vue warn]: Error in von handler (Promises/async): "TypeError: Cannot read properties of undefined (reading '$refs')" which causes the whole cascade of functions calls to collapse and none of these methods are being triggered.有时会发生错误:[Vue warn]: Error in von handler (Promises/async): "TypeError: Cannot read properties of undefined (reading '$refs')" 这会导致整个级联函数调用崩溃和这些方法都没有被触发。 The methods and the data are located in the child components.方法和数据位于子组件中。 What issue can cause that behavior?什么问题会导致这种行为?

Sounds like some of the child components are not completely mounted when you run your code.运行代码时,听起来有些子组件没有完全安装。 When are you running this code on the parent element?您何时在父元素上运行此代码?

You could fire an event from each of the child components upon mount, then run your code after all of them have been mounted.您可以在挂载时从每个子组件触发一个事件,然后在所有子组件都挂载后运行您的代码。

<child-component @hook:mounted="doSomething" />

(Example found here: Vue JS 2.0 Child Component Mounted Callback ) (此处找到示例: Vue JS 2.0 Child Component Mounted Callback

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 Vue.JS - Api 请求 - 未捕获(承诺中)TypeError:无法读取未定义的属性(读取“报价”) - Vue.JS - Api request - Uncaught (in promise) TypeError: Cannot read properties of undefined (reading 'quote') Vue.js 错误:TypeError:无法读取未定义的属性 - Vue.js error: TypeError: Cannot read properties of undefined TypeError:无法使用 VueJS 读取未定义的属性(读取 '$refs') - TypeError: Cannot read properties of undefined (reading '$refs') with VueJS Alpine JS - 错误:未捕获类型错误:无法读取未定义的属性(读取'_x_refs') - Alpine JS - Error : Uncaught TypeError: Cannot read properties of undefined (reading '_x_refs') “类型错误:无法读取未定义的属性‘服务’”Vue.js + Vuefire - "TypeError: Cannot read property 'servicios' of undefined" Vue.js + Vuefire TypeError:无法读取未定义的属性“标题”。 Vue.js - TypeError: Cannot read property 'title' of undefined. Vue.js Vue.js TypeError:消息无法读取未定义的属性“ singlePost” - Vue.js TypeError: Message Cannot read property 'singlePost' of undefined TypeError:无法读取未定义的Flatpickr&Vue.js属性“ add” - TypeError: Cannot read property 'add' of undefined" Flatpickr & Vue.js Vue.js - 类型错误:无法读取未定义的属性“标题” - Vue.js - TypeError: Cannot read property 'title' of undefined “无法读取未定义事件的属性”Vue.JS - 'Cannot read properties of undefined events' Vue.JS
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM