[Vuejs]-I want to change audio source onClick

0👍

You have to use a timer to make sure the DOM has been updated before you interact with the element like

    data() {
    return {
      audioSrc: ''
    }
  },
  methods: {
    setActiveAudio(item) {
      this.audioSrc = item;

      var element = this.$refs.audioElm;
      setTimeout(function()
      {
        element.currentTime = 0;
        element.crossOrigin = 'anonymus';
        element.play();      
      }, 0);
    },
  }

Working example on https://jsfiddle.net/AndersBillLinden/6x8hzrga/

Leave a comment