How to use the inject function from vue

Find comprehensive JavaScript vue.inject code examples handpicked from public code repositorys.

38
39
40
41
42
43
44
45
46
47
    type: Array,
    default: () => [],
  },
},
setup(props) {
  const rootTabs = vue.inject('rootTabs');
  if (!rootTabs) {
    throw new Error(`ElTabBar must use with ElTabs`);
  }
  const instance = vue.getCurrentInstance();
fork icon3
star icon8
watch icon3

+ 7 other calls in file

40
41
42
43
44
45
46
47
48
49
    queryChange: 'elOptionQueryChange',
    groupQueryChange: 'elOptionGroupQueryChange',
};

function useOption(props, states) {
    const select = vue.inject(selectKey);
    const selectGroup = vue.inject(selectGroupKey, { disabled: false });
    const isObject = vue.computed(() => {
        return Object.prototype.toString.call(props.value).toLowerCase() === '[object object]';
    });
fork icon1
star icon2
watch icon1

+ 5 other calls in file

64
65
66
67
68
69
70
71
72
73
        displayTooltip,
        hideTooltip,
    };
};
const useSliderButton = (props, initData, emit) => {
    const { disabled, min, max, step, showTooltip, precision, sliderSize, formatTooltip, emitChange, resetSize, updateDragging, } = vue.inject('SliderProvider');
    const { tooltip, tooltipVisible, formatValue, displayTooltip, hideTooltip, } = useTooltip(props, formatTooltip, showTooltip);
    const currentPosition = vue.computed(() => {
        return `${(props.modelValue - min.value) / (max.value - min.value) * 100}%`;
    });
fork icon1
star icon2
watch icon1

26
27
28
29
30
31
32
33
34
35
},
setup(props) {
    const index = vue.ref(-1);
    const lineStyle = vue.ref({});
    const internalStatus = vue.ref('');
    const parent = vue.inject('ElSteps');
    const currentInstance = vue.getCurrentInstance();
    vue.onMounted(() => {
        vue.watch([() => parent.props.active, () => parent.props.processStatus, () => parent.props.finishStatus], ([active]) => {
            updateStatus(active);
fork icon1
star icon2
watch icon1

40
41
42
43
44
45
46
47
48
49
    updateAll: Boolean,
},
setup(props, { slots }) {
    const el = vue.ref(null);
    const elForm = vue.inject(elFormKey);
    const elFormItem = vue.inject(elFormItemKey);
    const computedWidth = vue.ref(0);
    vue.watch(computedWidth, (val, oldVal) => {
        if (props.updateAll) {
            elForm.registerLabelWidth(val, oldVal);
fork icon1
star icon2
watch icon1

+ 5 other calls in file

109
110
111
112
113
114
115
116
117
118
  breadcrumb,
  title,
  desc,
  hasPermission
} = vue.toRefs(props);
const globalEASILocale = vue.inject("globalEASILocale", {
  message: {}
});
const route = vueRouter.useRoute();
const {
fork icon1
star icon1
watch icon4

240
241
242
243
244
245
246
247
248
249
const prismThemeSolarizedlight = undefined('prismjs/themes/prism-solarizedlight.css', { eager: true, as: 'raw' });
const prismThemeTomorrow = undefined('prismjs/themes/prism-tomorrow.css', { eager: true, as: 'raw' });
const prismThemeTwilight = undefined('prismjs/themes/prism-twilight.css', { eager: true, as: 'raw' });
// -------------------------------------------------- Emits & Slots & Injects //
const slots = vue.useSlots();
const codeBlockGlobalOptions = vue.inject('codeBlockGlobalOptions');
// -------------------------------------------------- Props //
// -------------------------------------------------- Data //
const copyTextValue = vue.ref('');
const convertedCode = vue.ref(null);
fork icon0
star icon1
watch icon1

10
11
12
13
14
15
16
17
18
19
20
21
22
var storeKey = 'store';


function useStore (key) {
  if ( key === void 0 ) key = null;


  return vue.inject(key !== null ? key : storeKey)
}


/**
 * Get the first item that pass the test
fork icon0
star icon0
watch icon1

+ 21 other calls in file

48
49
50
51
52
53
54
55
56
57
    }
},
emits: ["clickEntry", "toggleCollapsed", "updateLayerSize"],
setup: function (props, _a) {
    var emit = _a.emit, slots = _a.slots;
    var activeID = vue.inject("BtbVueList-activeEntryID");
    var collapsedSet = vue.reactive(new Set());
    var refList = vue.reactive({});
    var slotList = vue.computed(function () {
        return Object.keys(slots);
fork icon0
star icon0
watch icon1

1858
1859
1860
1861
1862
1863
1864
1865
1866
1867
function onBeforeRouteLeave(leaveGuard) {
    if (!vue.getCurrentInstance()) {
        warn('getCurrentInstance() returned null. onBeforeRouteLeave() must be called at the top of a setup function');
        return;
    }
    const activeRecord = vue.inject(matchedRouteKey, 
    // to avoid warning
    {}).value;
    if (!activeRecord) {
        warn('No active route record was found when calling `onBeforeRouteLeave()`. Make sure you call this function inside of a component child of <router-view>. Maybe you called it inside of App.vue?');
fork icon0
star icon0
watch icon1

+ 107 other calls in file

751
752
753
754
755
756
757
758
759
760
761
    }
    const metaProxy = manager.addMeta(source, vm);
    return metaProxy;
}
function useActiveMeta() {
    return vue.inject(metaActiveKey);
}


const MetainfoImpl = vue.defineComponent({
    name: 'Metainfo',
fork icon0
star icon0
watch icon1

+ 3 other calls in file

2342
2343
2344
2345
2346
2347
2348
2349
2350
2351
compatConfig: { MODE: 3 },
setup(props, { attrs, slots }) {
    warnDeprecatedUsage();
    const injectedRoute = vue.inject(routerViewLocationKey);
    const routeToDisplay = vue.computed(() => props.route || injectedRoute.value);
    const injectedDepth = vue.inject(viewDepthKey, 0);
    // The depth changes based on empty components option, which allows passthrough routes e.g. routes with children
    // that are used to reuse the `path` property
    const depth = vue.computed(() => {
        let initialDepth = vue.unref(injectedDepth);
fork icon0
star icon0
watch icon0

+ 44 other calls in file