I found that vue checks all the inject value and throw a warn when development and null. I think it's not reasonable, here is the case:
we use provide/inject mixin to maintain the z-index for some popper component.
In our standard, z-index of tip is 100, dialog is 2000. Without the mixin, it's difficult to maintain the z-index when a tip in a dialog. With the provide/inject mixin, the tip in a dialog, the index will be 2001 while we do nothing extra in css.
In this case, the inject 'zIndexBase' is not necessary. the first popper component just use it's own zIndex. But in latest vue, it throw a warn.......
export default {
provide() {
return {
zIndexBase: this.calcZIndex
};
},
inject: ['zIndexBase'],
props: {
zIndex: {
type: Number,
default: 0
}
},
computed: {
calcZIndex() {
if (!this.zIndexBase) {
return this.zIndex;
}
return this.zIndexBase this.zIndex / 100;
},
calcStyle() {
return {
zIndex: this.calcZIndex
};
}
}
};
the inject value can accept an object:
[{'key': 'keyItem', 'required': true}, 'zIncdexBase']
There is also a request ask for default injections (https://github.com/vuejs/vue/issues/6097), maybe we could consider them together.
Can you showcase the problem on a minimal jsfiddle?
To me it looks ilke you're looking for default values, so, as @jkzing said, I'll keep the other issue opened instead
Yes, this issue can be considered with #6097 together. Our purpose is to avoid the warning for missing inject.
Most helpful comment
Yes, this issue can be considered with #6097 together. Our purpose is to avoid the warning for missing inject.