0
我只想在方法返回的对象内显示'name'值。Vuejs在由方法返回的对象中显示一个值
当前显示的是:[{ “城市”: “渥太华”, “名”: “参议员”, “省”: “安大略”, “.KEY”: “-Kp00XARET2EDFRZVMks”}]
我想显示的是“参议员”。
这里是我的代码片段:
... in the template
<td>{{props.item.away}} {{ teamDetail(props.item.away) }}</td>
... in the script
methods: {
teamDetail(inpt) {
return this.teams.filter((team) => {
return team['.key'] == inpt;
})
},
props.item.away是发送到teamDetail检索特定团队的对象。关键,该对象在这种情况下返回是[{ “城市”:“渥太华”,“名称”:“参议员”,“省”:“安大略省”,“.key”:“-Kp00XARET2EDFRZVMks”}]
只显示“名称”模板{{teamDetail(props.item.away).name}}和方法中的过滤器中
我还试图使用计算,但我不能与 'this.props.item.away'
computed: {
teamDtl() {
return this.teams.filter((team) => {
return team['.key'] == this.props.item.away;
})
},
该对象被包装在一个数组中。是否{{teamDetail(props.item.away)[0] .name}}' –
{{teamDetail(props.item.home)[0]}}确实隔离了对象,{{teamDetail(props.item。 home)[0] .name}}会生成以下错误:渲染函数错误:“TypeError:无法读取未定义的属性'名称' – gvon79
您需要检查未定义的,然后。可能会变得很复杂,你应该为它计算一下,而不是试图将表达式放在你的模板中。 –