我确定我不是唯一一个与VueJS2有这个问题的人。
我使用axios返回一个" person"数组,如何访问" name"来自人的父母模特,公司的属性?
在laravel中,我可以像这样访问它: $ person - >公司 - >名字
但如果我在VueJs2中执行person.company.name,则会出错。 请帮忙,非常感谢!
错误是:
vue.js:526 TypeError: Cannot read property 'name' of undefined
at eval (eval at makeFunction (vue.js:9263), <anonymous>:2:662)
at Proxy.renderList (vue.js:3647)
at Proxy.eval (eval at makeFunction (vue.js:9263), <anonymous>:2:507)
at VueComponent.Vue._render (vue.js:3873)
at VueComponent.updateComponent (vue.js:2419)
at Watcher.get (vue.js:2756)
at Watcher.run (vue.js:2826)
at flushSchedulerQueue (vue.js:2595)
at Array.<anonymous> (vue.js:658)
at nextTickHandler (vue.js:605)
这是我用来创建&#34;人员的代码&#34;响应
$searchterms = explode(' ',$searchterm);
$person = (new Person)->newQuery();
foreach($searchterms as $searchterm) {
$person -> WhereHas('company', function($query) use($searchterm) {
$query->where('name','like','%'.$searchterm.'%');
});
}
$persons = $person -> get();
return $persons;