-
-
Notifications
You must be signed in to change notification settings - Fork 33.7k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
this
undefined in filters
#5998
Comments
This is intentional in 2.x. Filters should be pure functions and should not be dependent on |
You can take Also, I think it's better to support For example, if we have fn1, fn2 and fn3, and the code like this |
I think I encountered a case in which it would be nice to have a context in a filter. I'm creating an geometry–visualization app, the core module is a projection of a real coordinate space on the screen. And there are objects at this space represented as vue components. I though filters would do the trick: <canvas-component>
<cavas-object
:x="x | toPixelX"
:y="y | toPixelY"/>
</canvas-component> Props I understand that I can use methods, and I'm actually using 'em. But I'm wondering if there are some options in my case. |
I believe that there are some use cases that we need to access And we can also implement it in a hacky way which overwrite However, it is just something Filter related source codes: |
I'm absolutely convinced that filters must have a way access the context. The question's what core team is going to do about it? |
Yes I agree, there should be an option to use vue context in the filter, similar to child components. E.g. to be able to access parent component. I don't see the reason why filters should be pure functions. The pipe syntax looks better and is more readable than method calling, e.g. in number formatting where I need to access locale set on parent component: |
i also agree with component context in filters, if not, there is no point in providing per-component filters as opposed to global filters. my point is, you should be able to access the component from a component filter, but not able to access component from a global filter |
Actually there is. Different third-party components may use different filters with the same name. You need this isolation to prevent collisions. |
Sorry but my opinion has not changed: filters should not, and will not have access to context. If you need context, use a method. |
Version
2.3.4
Reproduction link
https://jsfiddle.net/xweeqtuw/1/
Steps to reproduce
open the fiddle
What is expected?
this
to be the componentWhat is actually happening?
this
is undefined in commonJS andwindow
in jsfiddle.Is this intentional, or should
this
be the component? I'd expect it to be the component.Is this a good candidate for my first PR? 😄
The text was updated successfully, but these errors were encountered: