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

231
Views
Vue.js lee blob como objeto/cadena a variable de aplicación

Tengo una aplicación vue con

 data: function() { return { modules: [], ...

Y método:

 methods: { submitted: function(){ ... axios({method: 'get', url: 'http://' + document.location.host + '/api/execute?commands=' + encodeURI(JSON.stringify(commands)), responseType: "blob"}).then(response => { if (response.headers['content-type'] === 'image/jpeg'){ this.modules[current]['results']['image']['visible'] = true this.modules[current]['results']['text']['visible'] = false const url = window.URL.createObjectURL(response.data) this.modules[current]['results']['image']['value'] = url } else{ this.modules[current]['results']['image']['visible'] = false this.modules[current]['results']['text']['visible'] = true var reader = new FileReader(); reader.onload = function(e) { // reader.result contains the contents of blob as a typed array console.log(e) this.modules[current]['results']['text']['value'] = reader.result } reader.readAsArrayBuffer(response.data); } ...

Esto debería solicitar algunos datos del servidor y mostrarlos como texto o imagen según la respuesta del servidor.

 *v-for module in modules earlier* <div class="resultText" :visibility=module.results.text.visible> {{ module.results.text.value }} </div> <div class="resultImage" :visibility=module.results.image.visible> <img :src=module.results.image.value> </div>

Pero el método da un error js cuando se devuelve el texto: TypeError: this.modules is undefined
El error en esta cadena:

 this.modules[current]['results']['text']['value'] = reader.result

Con imágenes funciona bien.
Con self.modules da lo mismo: TypeError: self.modules no está definido

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

0

Resolvió el problema con:

 response.data.text().then(text => { this.modules[current]['results']['text']['value'] = text });
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!