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

247
Visualizações
How to display dynamic variable in HTML

I'm wondering how to display a number in HTML that was created dynamically later on in the code. For instance I initialize the value reportDataLength in data(), and I tested that it was returning the right value by doing a console.log(), but now I want to display this value in HTML?

  name: 'notification-tray',
  data() {
    return {
      headers: [
        {
          text: 'Notifications',
          value: 'Body',
          width: '380px',
        },
      ],
      reportData: [],
      reportDataLength: 0,
    };
  },
  async created() {
    await this.getReportDataLength();
  },
  methods: {
    async getReportDataLength() {
      ... this.reportDataLength = this.reportData.length;
      
      console.log(this.reportDataLength);
    },
  },
};

But obviously when I do something like this,

      <span class="d-none">Notification Button</span>
      <span class="badge">this.reportDataLength</span>

it doesn't work correctly. The other solutions I saw for similar problems used JQuery, and I feel like there's a simple way to reference this, but I can't seem to find it out.

about 4 years ago · Juan Pablo Isaza
2 Respostas
Responde à pergunta

0

okay so if you are using pure Javascript , u can use this in your javascript function :

Document.getElementsByClassName('badge').innerHtml=this.reportDataLength ; 

otherwise if you are using vue js you can try something like this in your html file :

      <span class="badge">{{reportDataLength}}</span>
about 4 years ago · Juan Pablo Isaza Relatório

0

You can do document.getElementById("ID-HERE").innerHTML = "new stuff", but be warned that setting innerHTML is dangerous.

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