Vue: computed as a function

Created on 21 Mar 2017  路  4Comments  路  Source: vuejs/vue

What problem does this feature solve?

I have some case, when it will be very useful: fiddle
In this case creation of properties in constructor by custom function like:
computed { ...putSomeProps() }
does not fit, because there used information, created with inheritance chain of components.
And may be it will also useful in the case of vuex store bindings.

What does the proposed API look like?

computed() { return {prop1() {...}} }

feature request

Most helpful comment

Ha, I thought about this when I saw at #5237 but I think that if your computed functions cannot be defined right away and therefore depends on some external state to the component, they don't belong to that component

All 4 comments

I don't see any benefits from this feature and it seems a lot complex compared to current API.

Ha, I thought about this when I saw at #5237 but I think that if your computed functions cannot be defined right away and therefore depends on some external state to the component, they don't belong to that component

IMHO, component definition is designed to be static. For example, you cannot dynamically add methods , nor can you add reactive data fields on root after initialization. Adding this API would promote very high dynamism to Vue, which I'm skeptical about its benefit.

Users can simply return a dynamic object definition for a dynamic component. That's fairly easy.

I don't really think this is a good idea, largely what @HerringtonDarkholme has pointed out.

Was this page helpful?
0 / 5 - 0 ratings