[英]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 ...
Filters are not bound to the component instance.过滤器不绑定到组件实例。 Use a method instead.改用一种方法。
https://forum.vuejs.org/t/why-does-this-inside-a-filter-function-is-undefined/18321 https://github.com/vuejs/vue/issues/5998 https://forum.vuejs.org/t/why-does-this-inside-a-filter-function-is-undefined/18321 https://github.com/vuejs/vue/issues/5998
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.