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

151
Visualizações
How to set default v-model value from HTML?

I'm using twig with vue.js and I need to render dynamic form dependent on fields list returned from twig. Main problem here is that I cant pass fields list in Vue.js script and need to set default value from html

Input looks like this( {{ }} is twig brackets, not vue.js)

id="{{ id }}_input"
class="{{ id }}_input {{ type }}_input"
label="{{ label ?? null}}{{ meta.required ? " *" : null }}"
name={{ name }}
value={{ default ?? null }}
v-model="inputs['{{ id }}']"

I tried to do something like this

:inputs['{{id}}'] = "{{ default }}"

:inputs.{{id}} = "{{ default }}"

With no success. I also tried to map inputs keys on mount and get input values with document.getElementById, but inputs variable is always empty. Also I tried to get all form inputs on mount like this

 this.$el.querySelectorAll('input')

but in such case input value is always empty.

At this moment I'm using this hack, but this is absolutely awful imo, is there any other way to do it?

input

tmpValue="{{ default ?? null }}"

Vue.js

mounted() {
  this.$el
      .querySelectorAll('input')
      .forEach(input => {
          input.value = input.getAttribute('tmpValue')
          input.dispatchEvent(new Event('input'))
      });
}
about 4 years ago · Juan Pablo Isaza
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