插件名称 | vue-use-sound |
---|---|
版本号 | v1.1.5 |
发布时间 | 2020年12月15日 |
插件作者 | Tahul |
use-sound是一个轻巧的Vue挂钩,用于基于Vue Composition API和Howler.js在应用程序上播放声音效果。
v1.1.5(02/20/2021)
v1.1.3(02/07/2021)
v1.1.2(01/13/2021)
v1.1.0(01/12/2021)
v1.0.9(01/10/2021)
v1.0.5(01/03/2021)
v1.0.3(20年1月2日)
# Yarn
$ yarn add vue-use-sound
# NPM
$ npm i vue-use-sound
1.如下导入使用声音挂钩和声音效果文件:
import useSound from 'vue-use-sound'
import buttonSfx from '/path/to/effect.mp3'
export default {
setup() {
const [play] = useSound(buttonSfx)
return {
play,
}
},
}
2.启用一个按钮以播放声音效果。
<button @click="play">播放声音</button>
3.可用选项。
export interface HookOptions {
volume?: number
playbackRate?: number
interrupt?: boolean
soundEnabled?: boolean
sprite?: SpriteMap
onload?: () => void
}
export interface PlayOptions {
id?: number
forceSoundEnabled?: boolean
playbackRate?: number
}