背景音乐用的是audio标签
在使用audio标签时,他不会自动播放,受播放器的限制,需要用户互动,这里我写个dome,复制即用
//页面
<template>
<div @click="handleClick">off/on</div>//这里可以用个图标
<div v-if="shoes">
<div v-html='audios'> </div>
</div>
</template>
//data定义
data:{
shoes:false,
audios:'',
}
//交互
handleClick(){
if(this.shoes == false){
this.shoes = true;
this.audios='<head><audio src="https://win-web-rg01-sycdn.kuwo.cn/fb2ded11652cc69d6aec39cd7f233b00/6000f554/resource/n2/93/96/1872412330.mp3" play="true" loop="true" autoplay="autoplay"/> </head>';
}else if(this.shoes ==true){
this.shoes = false;
this.audios="";
}
}