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

252
Views
El complemento Nuxt no puede acceder a la instancia 'this' de Vue en los bloques de funciones

Así que logré inyectar hls.js para trabajar con el elemento nuxtjs $root y this

Lo hice así haciéndolo así (hls.client.js):

 import Hls from 'hls.js'; export default (context, inject) => { inject('myhls', Hls) }

y nuxt.config.js

 plugins: [ '~plugins/hls.client.js', ],

Esto funciona muy bien, literalmente :-) pero no puedo hacer referencia a 'esto' en los eventos de hls.

 playHls() { this.playing = true if(this.$myhls.isSupported()) { this.hls = new this.$myhls(); this.audio = new Audio(''); this.hls.attachMedia(this.audio); this.hls.loadSource(this.scr_arr[2]); this.audio.play() // 'THIS' DOES NOT WORK INSIDE this.hls.on this.hls.on(this.$myhls.Events.MEDIA_ATTACHED, function () { console.log(this.scr_arr[2]); // DOES NOT LOG console.log("ok") // works great }); // 'THIS' DOES NOT WORK INSIDE this.hls.on this.hls.on(this.$myhls.Events.MANIFEST_PARSED, function (event, data) { console.log('manifest loaded, found ' + data.levels.length + ' quality level') // WORKS console.log("ok") // WORKS this.audio.volume = 1 // DOES not work }); } },

Entonces, en estos eventos, no puedo usar nuxtjs 'esto', ¿porque parece haber un alcance diferente?

¿Puedo de alguna manera obtener 'este' alcance nuxt dentro de estos Eventos?

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

0

Reemplace sus funciones como

 this.hls.on(this.$myhls.Events.MANIFEST_PARSED, function (event, data) {

dentro

 this.hls.on(this.$myhls.Events.MANIFEST_PARSED, (event, data) => {

para mantener this contexto vinculado a la aplicación Vue, de lo contrario, se limitará al contexto del alcance del bloque.

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!