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

219
Visualizações
Vue.js - Use instance globalproperty as default value in component prop

Is there any way for me to access a global property from my vue instance when setting a default prop value in my component?

I would like to do this

props: {
  id: {
    type: String,
    default: this.$utils.uuid
  }
}

I also tried wrapping it in an arrow function withous success

props: {
  id: {
    type: String,
    default: () => this.$utils.uuid
  }
}
about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

I don't think that this can be achievable the way you want it. This is because props is an object and are common between components instances. The solution you have is either using a global $utils or using an internal data item instead of using directly the prop id in your component:

Using an internalId data item:

export default {
  props: {
    id: {
      type: String,
      default: null
    }
  },
  data () {
    return {
      internalId: this.id || this.$utils.uuid
    }
  }
}

Using the global Vue object

(this solution depends on how you register your utils plugin:

import Vue from 'vue'

export default {
  props: {
    id: {
      type: String,
      default: Vue.$utils.uuid // Depends on how you registered your plugin
    }
  }
}
about 4 years ago · Juan Pablo Isaza Relatório
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