[英]Error in render: “TypeError: Cannot convert undefined or null to object” in vue js?
Everythings works fine and im also getting the data but im getting this javascript error.一切工作正常,我也得到了数据,但我得到了这个 javascript 错误。
I have following network request我有以下网络请求
data: {
patient: null
}
methods: {
//call methods to add patients
setPatient(patient) {
this.patient = patient;
},
}
//network request in navigation guard
async beforeRouteEnter(to, from, next) {
await axios
.post(route("api.patient.ids"), { ids: [to.params.id] })
.then((res) => {
if (res.data.length) {
next((vm) => {
// console.log(typeof res.data[0]);
vm.setPatient(res.data[0]);
});
}
});
},
somebody could explain whats causing the problem?有人可以解释导致问题的原因吗?
Place a v-if="patient"
on any template element which requires patient
to be an object.在要求
patient
为 object 的任何模板元素上放置一个v-if="patient"
。 Your patient
is null
initially, until the API call returns and you commit it.您的
patient
最初是null
,直到 API 调用返回并且您提交它。
In your case:在你的情况下:
<health-condition v-if="patient"
:patient="patient"
@openForm="toggleFormTable" />
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.