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

192
Views
javascript nativo HTML interno que no obtiene el contenido creado por vue

Tengo este div que quiero extraer el contenido.

 <div id="print" ref="print_data"> <h1>{{ age }}</h1> </div>

y traté de extraer los contenidos usando el HTML interno nativo

 console.log( document.querySelector('#print').innerHTML );

probado también refs

 console.log( this.$refs['print_data'].innerHTML );

y no puedo ver el contenido de #print div pero puedo ver el contenido de age creado por vue en la página. Cualquier ayuda, ideas por favor es muy apreciada.

Aquí está el código completo

 <div id="app"> <div id="print" ref="print_data"> <span>{{ age }}</span> <span>{{ name }}</span> </div> <button @click="print">Print</button> <button @click="print2">Print 2</button> <button @click="print3">Print 3</button> <button @click="print4">Print 4</button> </div> new Vue({ el: '#app', data: { age: 12, name: '' }, methods: { print: function(){ this.name = 'test'; console.log(document.querySelector('#print').innerHTML); // returns HTML but 'age' is missing, no content generated by vue }), print2: function(){ this.name = 'test'; console.log(this.$refs['print_data'].innerHTML); // returns HTML but 'age' is missing, no content generated by vue }), print3: function(){ this.name = 'test2'; console.log(this.$refs['print_data'].content.innerHTML); // returns error }), print4: function(){ this.name = 'test3'; console.log(this.$refs['print_data'].toString()); // returns [object HTMLDivElement] }), } });
about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

Descubrí que es porque vue no terminó de actualizar el DOM, lo que resultó en el problema, en su lugar, uso $nextTick() y lo envuelvo con async

 ( async function(){ await _this.$nextTick().then(() => { console.log(document.getElementById("print").innerHTML); }); })()

y está funcionando ahora.

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!