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

106
Views
Cómo transformar esto en una función en vuejs

Quiero traducir el título <h2>{{$t('vue.'+key.replace('contract_data.',''))}} :</h2> y los mensajes <li>{{error}}</li> , mi colega me dice que transforme todo en métodos en vuejs pero no sé cómo hacerlo. este es mi código:

 <div v-if="getError"> <div v-for="(_errors, key) in getError"> <b-alert v-for="error in _errors" show variant="danger" > <h2>{{ $t('vue.'+key.replace('contract_data.','')) }} :</h2> <li>{{ error }}</li> </b-alert> </div> </div>
over 4 years ago · Santiago Trujillo
1 answers
Answer question

0

Lo que tu colega quiere es que extraigas la lógica del HTML a Javascript.

Para resolver este problema, su código podría verse así:

template

 <div v-if="getError"> <div v-for="(_errors, key) in getError"> <b-alert v-for="error in _errors" show variant="danger" > <h2>{{ formatKey(key) }} :</h2> <li>{{ error }}</li> </b-alert> </div> </div>

script

 export default { methods: { formatKey (key) { return this.$t('vue.' + key.replace('contract_data.', '')) } } }

Bonificación: desde un punto de vista personal, sugeriría agregar un atributo key a sus directivas v-for . (Doc: https://vuejs.org/v2/guide/list.html#Maintaining-State )

over 4 years ago · Santiago Trujillo 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!