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

195
Views
I can not detect api data in innerHTML after call the API

I am facing a problem catching innerHTML after calling the API using Axios in Vue js.

here is my HTML code

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

I used 'v-html' because my requested data is HTML format.

Here are my vue.js scripts

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'));
},



})

up to this works good, but when I am trying to get innerHTML from sourceText in activate function it not work.

I consoled in both functions, the result shows

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

mounted null

The result should look like this:

<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>

I would like to detect the p element inside the div tag

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

0

You need to wait for response, try:

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!