Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

227
Vistas
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 Respuestas
Responde la pregunta

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 Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda