Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/439.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript TypeError:无法读取未定义的已加载属性_Javascript_Php_Laravel_Vue.js_Eager Loading - Fatal编程技术网

Javascript TypeError:无法读取未定义的已加载属性

Javascript TypeError:无法读取未定义的已加载属性,javascript,php,laravel,vue.js,eager-loading,Javascript,Php,Laravel,Vue.js,Eager Loading,我可以像下面这样用laravel加载值$comments=Comment::with(['repress','user'])->get(),将其传递给vue并显示,但随后会显示错误消息: "TypeError: Cannot read property 'avatar' of undefined" 我的模板如下所示: <template><li> {{comment.user.avatar}} </li></template> 首先,

我可以像下面这样用laravel加载值
$comments=Comment::with(['repress','user'])->get(),将其传递给vue并显示,但随后会显示错误消息:

"TypeError: Cannot read property 'avatar' of undefined"

我的模板如下所示:

<template><li>
    {{comment.user.avatar}}
</li></template>

首先,我无法对这样的属性进行任何设置:

<img src="{{comments.user.avatar}}"></img>

因为Vue的工作原理与我在react中使用的不同,所以语法实际上是:

<img :src="comments.user.avatar"></img>

其次,我有类型错误,因为正如人们所指出的,我确实缺少用户实例,但它不在提供的模板示例中,而是在我的意大利面代码中


建议:最好将关注点分开并创建几个不同的组件,而不是尝试使用一个组件并在任何地方设置标志,然后出现这样的错误,注意。

nah,它是单数的,我最好更改它并提供数据对象try
dd(comment)
并检查它是否有
user
值。不幸的是,该评论中未提供doesuser。检查comment.userif我显示
{{comment.user}
我只得到一个数组,如果我显示
{{comment.user.avatar}
我得到值,也提到了错误
<img src="{{comments.user.avatar}}"></img>
<img :src="comments.user.avatar"></img>