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

221
Visualizações
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 Respostas
Responde à pergunta

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 Relatório

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 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