Vue.js 依赖于另一个计算属性的计算属性
下面的代码产生错误“无法读取未定义的属性“form”: 然而,如果我删除了Vue.js 依赖于另一个计算属性的计算属性,vue.js,computed-properties,Vue.js,Computed Properties,下面的代码产生错误“无法读取未定义的属性“form”: 然而,如果我删除了alerts(),我就不会收到任何错误,我甚至可以控制日志boundary\u limits或high\u risk\u alerts 成功,这意味着定义了$refs.hemoBoundaryLimits和此。$refs.highRiskAlerts 因此,Vue.js在如何定义警报方面存在问题,但我认为没有问题 有什么线索吗?错误是因为您试图访问computed属性中的$refs。 在安装模板之前对计算的属性进行评估,因
alerts()
,我就不会收到任何错误,我甚至可以控制日志boundary\u limits
或high\u risk\u alerts
成功,这意味着定义了$refs.hemoBoundaryLimits
和此。$refs.highRiskAlerts
因此,Vue.js在如何定义警报方面存在问题,但我认为没有问题
有什么线索吗?错误是因为您试图访问computed属性中的$refs
。
在安装模板之前对计算的属性进行评估,因此hemoBoundaryLimits
是未定义的
您应该在安装的挂钩中访问$refs
作为解决方案,您可以通过使用@hook
事件知道何时安装组件来欺骗它:
<hemoBoundaryLimits @hook:mounted="isHemoBoundaryLimitsMounted = true" />
你到底有什么错误?
<hemoBoundaryLimits @hook:mounted="isHemoBoundaryLimitsMounted = true" />
data: () => ({
isHemoBoundaryLimitsMounted: false
}),
computed: {
boundary_limits () {
if (!this.isHemoBoundaryLimitsMounted) return
return this.$refs.hemoBoundaryLimits.form;
}
}