简体   繁体   English

无法在 Vue 组件过滤器中访问“this”

[英]Cannot access “this” in Vue compnent filter

The filter is defined in the component options like this:过滤器在组件选项中定义,如下所示:

Vue.extend({
  ...
  props: ['filterFn', ......],

  filters: {
    myFilter(value){
      return this.filterFn ? this.filterFn(value) : value;
    }
  },

  ...
});

And it uses a function that is passed as a property to the component.它使用 function 作为属性传递给组件。

But it doesn't work.但它不起作用。

It tells me that it Cannot read property filterFn of undefined...它告诉我它无法读取未定义的属性 filterFn ...

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM