Skip to content
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

Suggestion: automatically bind props default value functions to current vm #1382

Closed
OEvgeny opened this issue Oct 2, 2015 · 4 comments
Closed

Comments

@OEvgeny
Copy link

OEvgeny commented Oct 2, 2015

Sometimes we need to set objects/arrays as default values of property in props. In these cases we need to specify a function that will return default value (docs link).

My suggestion is to automatically bind this kind of functions to current vm. So we can get access to vm context.

Now there are in global context:

props: {
  myProp: {
    type: Object,
    default: function () {
      console.log(this) // Window
      return {}
    }
  }
}
@yyx990803
Copy link
Member

This is easy to implement, although I'm curious what particular use case do you have for it?

@OEvgeny
Copy link
Author

OEvgeny commented Oct 2, 2015

I came across this trying to migrate to 1.0. Since props are separated from data now, I can't implement logic that was in data function before. So, seems props default values are not so flexible as data for now.

In my case components can get some default values from local cache. Cache service is available in vm.

@yyx990803
Copy link
Member

I see, thanks for the explanation!

@OEvgeny
Copy link
Author

OEvgeny commented Oct 2, 2015

Thanks a lot, Evan!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants