【问题标题】:Vue.js error: Cannot read property 'filter' of undefinedVue.js 错误:无法读取未定义的属性“过滤器”
【发布时间】: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


【解决方案1】:

我已经修复了数组的声明

产品:[ { all-stuffs-here } ]

括号不见了

但现在它显示此错误:

无法读取未定义的属性“搜索”

【讨论】:

    猜你喜欢
    • 2020-10-22
    • 2021-12-31
    • 2021-12-31
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-08-13
    • 1970-01-01
    • 2021-12-26
    相关资源
    最近更新 更多