没有看到组件结构的完整实现,我怀疑数据没有在组件中初始化,或者绑定到src应该是 :src 。
:src
但是,有一个Vue-howler实现可以作为mixin。
安装: npm install vue-howler --save
npm install vue-howler --save
创建音频播放器组件:
<script> import VueHowler from "vue-howler"; export default { mixins: [VueHowler] }; </script> <template> <div> <span>Total duration: {{ duration }} seconds</span> <span>Progress: {{ progress * 100 }}%</span> <button @click="togglePlayback">{{ playing ? "Pause" : "Play" }}</button> <button @click="stop">Stop</button> </div> </template>
在视图实例中使用它:
<script> import AudioPlayer from "./components/audio-player.vue"; export default { components: { AudioPlayer }, data() { return { audioSources: ["http://www.hochmuth.com/mp3/Haydn_Cello_Concerto_D-1.mp3"] }; } }; </script> <template> <div><audio-player :sources="audioSources" :loop="true"></audio-player></div> </template>
codesandbox: 演示