1

我想用wavesurfer.js在Vue中显示一个wav文件,我的代码:

     var wavesurfer = WaveSurfer.create({
          container: '#waveform',
          waveColor: 'red',
          progressColor: 'purple'
        });

     wavesurfer.load('https://ia902606.us.archive.org/35/items/shortpoetry_047_librivox/song_cjrg_teasdale_64kb.mp3');

     new Vue({
          el: '#app',
          data: {
            message: 'data1'
          },
        })

但我得到错误:

Unknown custom element: <wave> - did you register the component correctly? For recursive components, make sure to provide the "name" option.
4

1 回答 1

2

我找到了解决办法!

https://forum.vuejs.org/t/how-to-use-wavesurfer-with-vuejs-solved/14924

就这样写:

new Vue({
  el: '#app',
  data: {
    message: 'Hello Vue.js!'
  },
  mounted () {
    this.$nextTick(() => {
      this.wavesurfer = WaveSurfer.create({
          container: '#waveform',
          waveColor: 'blue',
          progressColor: 'purple'
      })
      this.wavesurfer.load('https://ia902606.us.archive.org/35/items/shortpoetry_047_librivox/song_cjrg_teasdale_64kb.mp3')
    })
  },
  methods: {
    play () {
        this.wavesurfer.playPause()
    }
  }
})
于 2018-05-10T04:13:12.027 回答