Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

219
Views
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 answers
Answer question

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 Report

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 Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!