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

289
Views
Mostrar un archivo XML en Nuxt

Recuperé el archivo del mapa del sitio en xml dinámicamente desde una url. Creé una vista especial para mostrar el contenido del archivo. En esta página, estoy usando axios para llamar a la URL y obtener el contenido.

Primero he creado un complemento axios

 export default function ({ $axios, error: nuxtError }, inject) { // Create a custom axios instance const xml = $axios.create({ headers: { common: { 'Content-Type': 'application/xml', 'Accept': 'application/xml' } } }) // If there is an error, this part of code will catch it and it will be handled by nuxt xml.onError((error) => { nuxtError({ statusCode: error.response ? error.response.code : error.status, message: error.message }) return Promise.resolve(error) }) // Inject to context as $xml inject('xml', xml) }

Luego, una página de muestra de vue con un método asyncData

 async asyncData({ $xml,$loader }: any) { // Initiate XML file content let xml!: string // Getting location sitemap's data const sitemap: any = await $loader.getSiteMap() if (sitemap?.resources) // Get the xml file content xml = await $xml.$get(sitemap.resources.secure_url) return { xml } } <template> <div> <pre>{{ xml }}</pre> </div> </template>

El contenido se recupera como una cadena de caracteres y no como un archivo xml. esto es normal porque cuando verifico el content-type en mi navegador encuentro que es text/html .

En el detalle de la respuesta obtenido de axios, el contenido es claramente xml y no una cadena

 headers: { connection: 'keep-alive', 'content-length': '2233', 'content-disposition': 'attachment; filename="sitemap.xml"', 'content-type': 'application/xml', etag: 'W/"effe5154abe7b53448d1f0b170119529"', 'last-modified': 'Wed, 19 Jan 2022 16:23:03 GMT', date: 'Thu, 20 Jan 2022 11:03:30 GMT', vary: 'Accept-Encoding', 'strict-transport-security': 'max-age=604800', 'cache-control': 'public, no-transform, immutable, max-age=2592000', 'server-timing': 'fastly;dur=2;cpu=1;start=2022-01-20T11:03:30.276Z;desc=hit,rtt;dur=17', server: 'Cloudinary', 'timing-allow-origin': '*', 'access-control-allow-origin': '*', 'accept-ranges': 'bytes', 'access-control-expose-headers': 'Content-Length,Content-Disposition,ETag,Server-Timing,Vary' }

No sé cómo puedo obligar a cambiar el tipo de contenido solo de esta página o encontrar una manera de interpretar mejor el archivo xml

about 4 years ago · Juan Pablo Isaza
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!