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

150
Views
Vue data() no está disponible en eventos cuando se usa @microsoft/fetch-event-source para eventos enviados por el servidor

Estoy tratando de usar fetchEventSource (de @microsoft/fetch-event-source ) para procesar eventos enviados por el servidor para transmitir datos al cliente. Funciona, ya que se devuelven los datos y puedo registrarlos en la consola, pero cuando intento actualizar mis datos de vue en el evento onmessage , aparece el error:

TypeError: Cannot set properties of undefined (setting 'messages')

¿Alguna idea sobre la mejor manera de hacer que esto funcione?

Plantilla de prueba básica:

 <template> <div> <p> <label>Message</label><br /> <textarea id="messages" v-model="messages"></textarea><br /> <button @click="getMessage">GET</button> </p> </div> </template>

y el guión:

 import { fetchEventSource } from "@microsoft/fetch-event-source"; export default { data() { return { messages: "", }; }, mounted() { this.messages = "initialized"; // this works }, methods: { getMessage() { fetchEventSource("url-here", { method: "POST", headers: { "Content-Type": "application/json", }, onmessage(msg) { console.log("message", msg.data); // this works - data is here! this.messages = msg.data; // this returns the error }, }); }, }, };
about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

Puedes probar con la función de flecha o como:

 getMessage() { const self = this fetchEventSource("url-here", { method: "POST", headers: { "Content-Type": "application/json", }, onmessage(msg) { console.log("message", msg.data); // this works - data is here! self.messages = msg.data; // this returns the error }, }); },
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!