VUE 2关于儿童组件的道具未定义
因此,我试图将道具传递给儿童组件,如下所示。
<Project :grossMarginPerResource="grossMarginPerResource" :threshold="threshold" :orderBy="orderBy" @refetch="refetch" v-if="group_by == 'Project'"></Project>
道具时,子组件都会接受此道具
props: ['grossMarginPerResource', 'orderBy', 'show_costs','threshold'],
每当我尝试访问此
,要么通过登录控制台,它将其打印为未定义,在父级中记录它,显示以下内容:
{ "green": "1000", "yellow": "400", "red": "400" }
但是,如果我在子组件中使用:
console.log(this.threshold)
它将打印出未定义的未定义
So I'm trying to pass a prop down to a child component as follows.
<Project :grossMarginPerResource="grossMarginPerResource" :threshold="threshold" :orderBy="orderBy" @refetch="refetch" v-if="group_by == 'Project'"></Project>
The child component accepts this prop
props: ['grossMarginPerResource', 'orderBy', 'show_costs','threshold'],
Whenever I try to access this prop, either by console logging it, it prints out as undefined,
Logging it in the parent component shows the following:
{ "green": "1000", "yellow": "400", "red": "400" }
but if I do in the child component:
console.log(this.threshold)
it prints out undefined
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
它应该有效,要找到根本原因,我刚刚创建了此代码段,并且根据您上面提到的代码正常工作。您能在所有生命周期挂钩中返回
threshold
数据,请浏览一下您面临哪个位置的问题。演示:
It should work, To find the root cause I just created this code snippet and it is working fine as per the code you mentioned above. Can you please have a look and confirm at which place you are facing issue as
console.log
will return thethreshold
data in all the life cycle hooks.Demo :