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

144
Visualizações
appending vuejs data to a div

I have something I have been trying to do which is challenging. I have a simple div that gets appended to the top level on the click of a button. The issue is I want vuejs data appended inside of this div. I am not quite sure how to bind this data, I have tried using a simple expression, but no luck. Can someone please let me know how this can be solved--and with a div, not a bootstrap modal

new Vue({
  el: "#app",
  data: {
  chocs:[{"title":'a man tale'},{"title":'a boy tale'}]
    
  },
  methods: {
 handleTileClick: function(){
  alert(this.chocs[0].title);
     
   $("#fox").append(`<div id="popover-dialog"> data here {{this.chocs[0].title}}
</div>`);
   
   },
  }
})
<script src="https://cdnjs.cloudflare.com/ajax/libs/vue/2.5.17/vue.js"></script>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.5.1/jquery.min.js"></script>

<div id="app">
  <h2>Todos:</h2>
 <button v-on:click="handleTileClick()">
 Click Me
 </button>
 <div id="fox">
 
 </div>
</div>

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

0

Without JQuery, the Vue-way:

new Vue({
  el: "#app",
  data: () => ({
    chocs:[{"title":'a man tale'}, {"title":'a boy tale'}],
    titleToBeAppended: ''
  }),
  methods: {
    handleTileClick: function(){
        this.titleToBeAppended = this.chocs[0].title
    }
  }
});
<script src="https://cdnjs.cloudflare.com/ajax/libs/vue/2.5.17/vue.js"></script>

<div id="app">
<div id="popover-dialog">
<p>Data here: {{ titleToBeAppended }}</p>
<button v-on:click="handleTileClick()">Click Me</button>
</div>
</div>

about 4 years ago · Juan Pablo Isaza Relatório

0

Using template literals:

new Vue({
  el: "#app",
  data: () => ({
    chocs:[{"title":'a man tale'}, {"title":'a boy tale'}]  
  }),
  methods: {
    handleTileClick: function(){
      alert(this.chocs[0].title); 
      $("#fox").append(
        `<div id="popover-dialog">data here: ${this.chocs[0].title}</div>`
      );
    }
  }
});
<script src="https://cdnjs.cloudflare.com/ajax/libs/vue/2.5.17/vue.js"></script>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.5.1/jquery.min.js"></script>

<div id="app">
  <h2>Todos:</h2>
  <button v-on:click="handleTileClick()">Click Me</button>
  <div id="fox"></div>
</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