[英]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.