A
A
Alexander2020-05-24 01:13:17
Vue.js
Alexander, 2020-05-24 01:13:17

Why is the value not assigned to the desired property?

I am writing a player, and it is necessary that the value I need is assigned to the isPulse property.
Section of code where it is not assigned:

onplay () {
this.isPulse = audio.id
},

Full code.
import { Howl } from 'howler'
import { PlayIcon } from 'vue-feather-icons'

export default {
  props: {
    audio: Object
  },
  data () {
    return {
      isTargeted: null,
      isPulse: null
    }
  },
  components: {
    PlayIcon
  },
  computed: {
    loading () {
      return this.$store.getters.loading
    }
  },
  methods: {
    startAudio (audio) {
      const audioTrack = new Howl({
        xhr: { method: 'POST' },
        src: [audio.audio],
        onplay () {
          this.isPulse = audio.id
        },
        onend () {
          this.isTargeted = null
        }
      })

      if (this.isTargeted === null) {
        this.isTargeted = audio.id
        audioTrack.play()
      } else {
        audioTrack.pause()
        this.isTargeted = null
      }
    }
  }
}

Answer the question

In order to leave comments, you need to log in

1 answer(s)
E
Evgeny Kuznetsov, 2020-05-24
@AlexVue

It seems to me that the problem is in the loss of context,
try replacing this:

onplay () {
this.isPulse = audio.id
},

on this:
onplay: () => {
this.isPulse = audio.id
},

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question