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

199
Views
No puedo detectar datos de api en innerHTML después de llamar a la API

Me enfrento a un problema al capturar el HTML interno después de llamar a la API usando Axios en Vue js.

aquí está mi código HTML

 <div id="vue-app"> <div id="sourceText" style="display: none" v-html="`${reqData}`"></div> </div>

Usé 'v-html' porque mis datos solicitados están en formato HTML.

Aquí están mis scripts vue.js

 var vueApp = new Vue({ el: '#vue-app', data(){ return{ reqData: null, } }, methods:{ getStory:function () { axios .get('https://api.coindesk.com/v1/myApi') .then((response) => (this.reqData = response.data.content)) .catch((error) => console.log('error SMS', error));}, }, activate: function () { var sourceText = document.getElementById('sourceText').innerHTML; this.line_array = sourceText.split(this.line_spliter); } }, beforeMount() { this.activate(); console.log('beforeMount', document.getElementById('sourceText')); }, mounted() { this.getStory(); console.log('mounted', document.getElementById('sourceText')); }, })

hasta esto funciona bien, pero cuando intento obtener HTML interno de texto fuente en la función de activación , no funciona.

Consolé en ambas funciones, el resultado muestra

beforeMount <div id=​"sourceText" style=​"display:​ none" v-html=​"`${reqData.content}​`">​</div>​

mounted null

El resultado debería verse así:

 <div id="sourceText" style="display:none"> <p>Lorem ipsum dolor sit.</p> <p>Lorem ipsum dolor sit.</p> <p>Lorem ipsum dolor sit.</p> <p>Lorem ipsum dolor sit.</p> </div>

Me gustaría detectar el elemento p dentro de la etiqueta div

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

Necesitas esperar respuesta, prueba:

 async getStory() { await axios .get('https://api.coindesk.com/v1/myApi') .then((response) => (this.reqData = response.data.content)) .catch((error) => console.log('error SMS', error));}, }, async mounted() { await this.getStory(); },
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!