Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

141
Views
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 answers
Answer question

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 Report

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 Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!