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

185
Views
vue change div from component

html:

    <div class='wrapper'>
      <div class='custom'>
        <div class='item'> 1</div>
        <div class='item'> 2 </div>
        <div class='item'> 3 </div>
      </div>
      <component-vue />
    </div>

Vue:

    methods: {
      doSomething() {
       document.querySelector('.custom).innerHTML = /new items
     }
    }

My question is, is this the only way to change the external div? I need to change items, new ones come from api. Maybe there is another way? If only through innerHTML, then how can I implement the idea?

over 4 years ago · Santiago Trujillo
1 answers
Answer question

0

For example,

<div class="item" v-for="(item, index) in items" :key="index"></div>
data() {
   return {
      items: []
   }
},
methods: {
    doSomething() {
       // Fetch data from api and load
       this.items = res.data
   }
}

EDIT

<div class='custom' v-html="dataHtml"></div>
data() {
   return {
      dataHtml: `
      <div>Initial html</div>
      `
   }
},
methods: {
    doSomething() {
       // Fetch data from api and load
       this.dataHtml = createHtml(res.data) // Fictional method to parse data and transform to html f.e.
   }
}
over 4 years ago · Santiago Trujillo 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!