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

218
Vistas
How to run Vue directive on page load?

I'm looping over an array of objects consisting of map svg paths and locales and want to run a function upon load. The function has to take the locale keys of the paths array as parameter and do something with it:

<p v-for="(country, locale) in paths" @load="myFunction(locale)">log {{locale}}</p>

but @load does nothing. The same code works with the @click directive:

<p v-for="(country, locale) in paths" @click="myFunction(locale)">log {{locale}}</p>

This is the function:

const myFunction = (locale) => {
    console.log(locale)
}

How do I make it work?

about 4 years ago · Juan Pablo Isaza
2 Respuestas
Responde la pregunta

0

<p v-for="(country, locale) in paths">log {{myFunction(locale)}}</p>

methods: {
    myFunction(locale) {
        // do something
    }
}

It's resolve your question?

about 4 years ago · Juan Pablo Isaza Denunciar

0

this sounds like directives are the wrong tools for the job. you seem to have all related variables in one array anyway, so why not iterate through the array in mounted? eg:

mounted() {
  this.paths.forEach((path) => {
    this.myFunction(path.locale);
  })
}

this could also be done in the created hook

Btw: You are not using directives here, @click and @load are just events and you register listeners to it. the element fires click on click but doesnt fire the load event, thats why it doesnt trigger your function. maybe you misunderstood what a directive is

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