【发布时间】:2019-03-01 12:14:54
【问题描述】:
我正在尝试在 Vue JS 的计算属性中执行 if / else 语句以进行搜索,这就是我所拥有的,但它不起作用,我该如何调整它以使其工作?
computed: {
filteredProperties: function(){
return this.properties.filter((property) => {
return property.address.match(this.searchAddress) &&
if (this.searchType.length > 1) {
this.searchType.some(function(val){
return property.type.match(val)
}) &&
} else {
property.type.match(this.searchType) &&
}
property.bedrooms.match(this.searchBedrooms) &&
property.county.match(this.searchCounty)
});
}
}
【问题讨论】:
-
it's not working在哪种情况下不起作用? -
-
像您使用的
&&是无效的...&& if (condition) {} &&是无效的。}) && } else {- 绝对无效。 -
@tymeJV 我怎样才能使它有效?
-
您可以使用三元组,也可以将
if逻辑的结果分配给一个变量,然后检查该变量。
标签: javascript vue.js vuejs2 nuxt.js