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

329
Visualizações
How do you update a vue interpolation using an onclick method?

I am struggling to update the interpolation of thing. This simple function should change the value of the data but instead does nothing. Chrome logs the change of thing in the console but the HTML does not update.

<template>
  <div class="container-xl pb-5">
    <button class="mb-2 btn-lg selected-dropdown" @click="dropSelect('B')">
      {{ thing }}
    </button>
  </div>

</template>

<script lang="ts">
import { defineComponent } from "vue";

export default defineComponent({
  data() {
    return {
      thing: "A",
    };
  },

  methods: {
    dropSelect(thing: any) {
      console.log(thing);
      return this.thing;
    },
  },
});
</script>
about 4 years ago · Juan Pablo Isaza
2 Respostas
Responde à pergunta

0

Try to update your data property instead of returning:

dropSelect(thing: any) {
  this.thing = thing
},
about 4 years ago · Juan Pablo Isaza Relatório

0

One small observation : Use this.thing = thing instead of return this.thing

Demo :

new Vue({
  el: '#app',
  data: {
    thing: "A"
  },
  methods: {
    dropSelect(thing) {
      this.thing = thing;
    }
  }
})
<script src="https://cdnjs.cloudflare.com/ajax/libs/vue/2.5.17/vue.js"></script>
<div id="app">
  <button @click="dropSelect('B')">
      {{ thing }}
    </button>
</div>

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