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

114
Visualizações
How to transform this to a function in vuejs

I want to translate the title <h2>{{$t('vue.'+key.replace('contract_data.',''))}} :</h2> and messages <li>{{error}}</li>, my collegue tell me that transform all into a methods in vuejs but i don't know how to do. this is my code:

<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 Respostas
Responde à pergunta

0

What your colleague wants is that you extract the logic from the HTML to Javascript.

To solve this problem, your code could look like that:

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.', ''))
    }
  }
}

Bonus: From a personal stand point I would suggest to add a key attribute to your v-for directives. (Doc: https://vuejs.org/v2/guide/list.html#Maintaining-State)

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