vue.js - 单击“selectAll”时以及在选择任何过滤器之前如何显示所有产品?
问题描述
**我正在使用 Vue 和 Firebase 创建一个网上商店。过滤器有效,但我希望它在选择特定过滤器之前显示所有产品。这是过滤器的链接,此外,我还有一个显示所有产品的链接:**
<v-list-item link>
<v-list-item-content @click="selectAll()">
<v-list-item-title>All Categories</v-list-item-title>
</v-list-item>
<v-list-item link>
<v-list-item-content @click="selectElectronics()">
<v-list-item-title>Electronics & Lights</v-list-item-title>
</v-list-item-content>
</v-list-item>
<v-list-item link>
<v-list-item-content @click="selectKitchen()">
<v-list-item-title>Kitchen</v-list-item-title>
</v-list-item-content>
</v-list-item>
<v-list-item link>
<v-list-item-content @click="selectHobbies()">
<v-list-item-title>Hobbies & Free-time</v-list-item-title>
</v-list-item-content>
</v-list-item>
<v-col
sm="5"
md="6"
v-for="item in filterCategoryItems"
:key="item.name"
>
**应该在计算中进行哪些更改以使其工作?它以前与注释行一起工作,但现在不再工作了我不知道为什么渲染中的错误:“TypeError:无法读取未定义的属性'包含'”**
export default {
data() {
return {
categoryChoice: "",
};
},
methods: {
selectAll() {
this.categoryChoice = "";
},
selectElectronics() {
this.categoryChoice = "electronics";
},
selectKitchen() {
this.categoryChoice = "kitchen";
},
selectHobbies() {
this.categoryChoice = "hobbies";
},
computed: {
filterCategoryItems() {
return this.menuItems.filter(
filterItem => filterItem.category == this.categoryChoice
// (filterItem) => filterItem.category.includes(this.categoryChoice)
);
},
menuItems() {
return this.$store.getters.getMenuItems;
},
basket() {
return this.$store.getters.getBasketItems;
},
favItems() {
return this.$store.getters.getFavItems;
},
},
};
解决方案
您的脚本未正确构建。如果你修复了缩进,你可能已经注意到了。data() 也应该返回一个对象:
<script>
export default {
data() {
return {
categoryChoice: ""
};
},
methods: {
selectAll() {
this.categoryChoice = "";
},
selectElectronics() {
this.categoryChoice = "electronics";
},
selectKitchen() {
this.categoryChoice = "kitchen";
},
selectHobbies() {
this.categoryChoice = "hobbies";
}
},
computed: {
filterCategoryItems() {
return this.menuItems.filter(
(filterItem) => filterItem.category == this.categoryChoice
// (filterItem) => filterItem.category.includes(this.categoryChoice)
);
},
menuItems() {
return this.$store.getters.getMenuItems;
},
basket() {
return this.$store.getters.getBasketItems;
},
favItems() {
return this.$store.getters.getFavItems;
}
}
};
</script>
推荐阅读
- excel - 如何将excel电子表格传输到access数据库
- flutter - 在 Flutter 中禁用 iOS 动态类型
- postgresql - postgresql 在创建较小的索引时是否使用较大的索引?
- sql - 如何避免无限循环?
- r - R:阶跃函数未在结果报告中写出完整模型
- python - 高级 Python 正则表达式:如何从多行字符串中评估和提取嵌套列表和数字?
- c - 如何解决此 int 溢出?
- python - Python args:为 django manage.py 设置的 django 调试 arg
- macos - 鱼壳修复表情符号间距 iTerm2 MacOS
- c# - SerialPort 发送丢失的字符