我有一个连接到Vue计算属性的选择框。我想知道为什么我的
computed
属性尝试有效,而其他尝试无效。
<select>
<option v-for="option in filteredItems">{{option.description}}</option>
</select>
filteredItems
是计算属性。此代码适用于:
vInstance = new Vue({
...
computed: {
filteredItems: function(){
let someID = this.filterID;
return this.allItems.filter(function(item){
return item.id === someID;
})
}
}
})
此版本没有
computed: {
filteredItems: function(){
return this.allItems.filter(function(item){
return item.id === this.filterID;
})
}
}
除了第一个版本设置的功能外,这两个功能几乎相同
this.filterID
要在过滤器中使用的其他变量。为什么这样做有效,而另一个不行?