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

Inject option in mixin no longer works #6093

Closed
kasperisager opened this issue Jul 13, 2017 · 5 comments · Fixed by #6107
Closed

Inject option in mixin no longer works #6093

kasperisager opened this issue Jul 13, 2017 · 5 comments · Fixed by #6107

Comments

@kasperisager
Copy link

kasperisager commented Jul 13, 2017

Version

2.4.1

Reproduction link

https://jsfiddle.net/d92sL0zy/2/

Steps to reproduce

  1. Create mixin that sets the inject option
  2. Create component that uses said mixin
  3. Use component in context with a corresponding provide

What is expected?

The data provided in the context is correctly injected into the component that uses the mixin with the inject option set.

What is actually happening?

The data provided is not injected into the component that uses the mixin, unless the inject option is specified directly on the component and not in the mixin.


I use the pattern of specifying provide and inject options on mixins extensively, as this provides some really useful mixins for specifying relationships between different components. A component using a hasOne() mixin would for example provide itself to a child which would then use a memberOf() mixin to inject the parent. As of Vue 2.4.0 , this however no longer works as the inject option of the memberOf() mixin is ignored.

@jkzing
Copy link
Member

jkzing commented Jul 13, 2017

Sorry, it should be introduced by #5827. My fault...😭

Will try to fix it...

@kasperisager
Copy link
Author

No worries! Reverted to 2.3.4 in the meantime, so no harm done 👌

@frandiox
Copy link

This also happens when trying to extend a component that implements inject with the new Vue({ extends: ... }); syntax. I guess it's the same issue.

@jkzing
Copy link
Member

jkzing commented Jul 18, 2017

@frandiox Yes, it's the same root cause, and will be fixed once #6098 or #6107 get merged.

Sorry for that...

@javoski
Copy link
Member

javoski commented Jul 18, 2017

Before this have been fixed, you can customize the merge strategy of inject option to make a workaround. Some kinda like:

Vue.config.optionMergeStrategies.inject = function (parent, child) {
  return Vue.util.extend(Vue.util.extend({}, parent), child)
}

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