【发布时间】:2020-01-12 05:31:19
【问题描述】:
我正在构建一个应用程序来使用 json 并使用搜索过滤器输入和其他内容列出它
我已经尝试过创建函数但没有成功
{
produtoFiltrado:function()
{
var self=this;
return this.produtos.filter(function(cust){
return cust.nome.toLowerCase().indexOf(self.search.toLowerCase())>=0;
});
}
}
显示此错误:无法读取未定义的属性“过滤器”
这里是codeandbox url: https://codesandbox.io/s/vue-template-7iev3?fontsize=14
【问题讨论】:
-
produtos 是一个数组吗?它依赖于 Promise 吗?尝试使用 if 之前的 if
this.produtos.filter测试 this.produtos 是否存在。另外,用console.log(this.produtos);检查它的值,因为它是 undefined -
@MatheusValenza 它缺少 produtos 数组的 [ ] 但现在可以了...实际上现在它显示另一个错误:无法读取未定义的属性“搜索”。但我已经定义了搜索
标签: vue.js search filter axios