Vue: Inject option in mixin no longer works

Created on 13 Jul 2017  路  5Comments  路  Source: vuejs/vue

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.

regression

Most helpful comment

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)
}

All 5 comments

Sorry, it should be introduced by https://github.com/vuejs/vue/pull/5827. My fault...馃槶

Will try to fix it...

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

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.

@frandiox Yes, it's the same root cause, and will be fixed once https://github.com/vuejs/vue/pull/6098 or https://github.com/vuejs/vue/pull/6107 get merged.

Sorry for that...

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)
}
Was this page helpful?
0 / 5 - 0 ratings

Related issues

bfis picture bfis  路  3Comments

wufeng87 picture wufeng87  路  3Comments

aviggngyv picture aviggngyv  路  3Comments

robertleeplummerjr picture robertleeplummerjr  路  3Comments

finico picture finico  路  3Comments