source-shell
npm i vue-wave-surfer
or
source-shell
yarn add vue-wave-surfer
As a global vue-cli plugin
source-js
import Vue from 'vue'
import VueWaveSurfer from 'vue-wave-surfer'
Vue.use(VueWaveSurfer)
As a nuxt global plugin
source-js
// plugins/vue-wave-surfer.js
import Vue from 'vue'
import VueWaveSurfer from 'vue-wave-surfer'
Vue.use(VueWaveSurfer)
source-js
// nuxt.config.js
export default {
plugins: [
'~/plugins/vue-wave-surfer'
]
}
As a component plugin
source-js
import VueWaveSurfer from 'vue-wave-surfer'
export default {
components: {
VueWaveSurfer
}
}
text-html-vue
<template>
<vue-wave-surfer :src="file" :options="options"></vue-wave-surfer>
</template>
<script>
export default {
data() {
return {
options: {
},
file: 'http://example.com/file.mp3'
}
}
}
</script>
See the list of options in the official documentation
An example implementing the Cursor plugin
text-html-vue
<script>
import Cursor from 'wavesurfer.js/dist/plugin/wavesurfer.cursor';
export default {
data() {
return {
options: {
plugins: [
Cursor.create()
]
}
}
}
}
</script>
This is a client-only module so be sure to wrap it in a client-only tag if using nuxt
text-html-vue
<vue-wave-surfer src="url.mp3" ref="surf"></vue-wave-surfer>
<script
export default {
mounted() {
this.player.on('ready', () => {
console.log('ready')
})
},
computed: {
player() {
return this.$refs.surf.waveSurfer
}
}
}
</script>
hunter-isaiah96/vue-wave-sufver
#vuejs #javascript #vue-js