Vue: Remove every error reporting/debugging of provide/inject, or allow require flag for inject

Created on 17 Jul 2017  ·  3Comments  ·  Source: vuejs/vue

What problem does this feature solve?

#5628

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

};

What does the proposed API look like?

the inject value can accept an object:

[{'key': 'keyItem', 'required': true}, 'zIncdexBase']

Most helpful comment

Yes, this issue can be considered with #6097 together. Our purpose is to avoid the warning for missing inject.

All 3 comments

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.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

asiFarran picture asiFarran  ·  34Comments

Akryum picture Akryum  ·  34Comments

yyx990803 picture yyx990803  ·  210Comments

karevn picture karevn  ·  36Comments

okjesse picture okjesse  ·  49Comments