Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

315
Visualizações
Vue.prototype global defined in app is undefined on components in dependency

I'm trying to create a common component library for two Vue applications, allowing the applications to define their own Vue.prototype.$someGlobal (specfically, an Axios instance). I'm trying to use this global from the shared component library, so that each app can have it's own Axios configuration and have the shared component use whichever is used.

However, while I have no problem accessing this.$someGlobal from components in the main package, if I refer to it in the common package it will be undefined.

Code:

# main.ts
import Vue from 'vue'
import App from './App.vue'

Vue.prototype.$someGlobal = 'some global';

new Vue({
  render: h => h(App),
}).$mount('#app')
# app/App.vue
<template>
  <div id="app">
    App
    <some-component />
  </div>
</template>

<script lang="ts">
import { Component, Vue } from 'vue-property-decorator';
import SomeComponent from "common-components/SomeComponent.vue"

@Component({
  components: {SomeComponent}
})
export default class App extends Vue {
  mounted() {
    console.log("this.$someGlobal in App:", this.$someGlobal)
  }
}
</script>
# common/SomeComponent.vue
<template>
  <span>some component</span>
</template>

<script lang="ts">
import { Component, Vue } from 'vue-property-decorator';

@Component
export default class SomeComponent extends Vue {
  mounted() {
    console.log("this.$someGlobal in SomeComponent:", this.$someGlobal)
  }
}
</script>

Console output when opening this app:

this.$someGlobal in SomeComponent: undefined
this.$someGlobal in App: some global

Demo repo: https://github.com/timraasveld/vue-prototype-with-common-package-demo

Can someone explain why this.$someGlobal is defined in components in the main /app package, but not in the dependency /common package? And how should I go about properly sharing a Vue global between the app and the component library?

I already tried making a mixin, but faced the same problem.

about 4 years ago · Juan Pablo Isaza
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda