这个问题可能有一个非常简单的解决方法,但我似乎无法让它正常工作。我正在使用 Vuetify 数据表来循环并显示我的所有属性,但是当我使用计算属性时它似乎无法正常工作。我正在尝试将一些道具(街道、城市、州、邮编)组合到一个计算地址道具中。因此,当我单独使用每个道具时,它可以像这样正常工作:
<td class="text-xs-center">{{ props.item.street }}</td>
<td class="text-xs-center">{{ props.item.city }}</td>
<td class="text-xs-center">{{ props.item.state }}</td>
<td class="text-xs-center">{{ props.item.zip }}</td>
Run Code Online (Sandbox Code Playgroud)
但是,如果在我的 Vue 模板的脚本部分,我创建了一个计算属性“fullAddress”,如:
computed: {
fullAddress () {
return this.street & '\n' & this.city & ', ' & this.state & ' ' & this.zip
}
}
Run Code Online (Sandbox Code Playgroud)
然后在上面的模板中使用它,例如:
<td class="text-xs-center">{{ props.item.fullAddress() }}</td>
Run Code Online (Sandbox Code Playgroud)
它根本不起作用。我也尝试了许多其他方法来写出来,但没有任何效果。我是 Vue 的新手以及它如何使用计算属性,所以我确信我只是不了解它是如何正常工作的。
编辑:我正在使用 Vuetify 数据表来循环我的数据。我正在使用他们的文档来显示表格。就像我说的,我是 Vue 的新手,所以我想弄清楚这一切。我相信 :items="items" 是所有道具的 v-bind(类似于 v-for 循环?)。下面是一个更完整的例子,展示了 Vuetify 对一个非常简单的数据表的作用:
<template>
<v-data-table
:headers="headers"
:items="items"
hide-actions
class="elevation-1"
>
<template slot="items" slot-scope="props">
<td>{{ props.item.name }}</td>
<td class="text-xs-right">{{ …Run Code Online (Sandbox Code Playgroud) 我有一个对象数组,我需要检查数组中是否已存在类似的对象。例如,是否存在具有相同品牌和型号属性的对象(福特福克斯):
{
make: 'Ford',
model: 'Focus',
color: 'red',
year: 2016
}
Run Code Online (Sandbox Code Playgroud)
在这个数组中?
[
{
make: 'Ford',
model: 'Focus',
color: 'blue',
year: 2008
},
{
make: 'Ford',
model: 'Mustang',
color: 'red',
year: 2011
},
{
make: 'Chevy',
model: 'Malibu',
color: 'blue',
year: 2012
},
{
make: 'Ford',
model: 'Focus',
color: 'black',
year: 1999
}
]
Run Code Online (Sandbox Code Playgroud)
我更喜欢 ES6 方法,但也可以使用 lodash。Lodash 有 _.some 但据我所知,它匹配整个对象(不仅仅是所需的特定属性)或仅匹配一个属性。此外,我需要类似 _.pullAllWith 的东西,我可以在其中删除包含这些特定属性的所有对象(即删除包含福特福克斯的所有对象)。