audio的使用

发布时间:2024年01月20日
<div style="width: 500px;height: 500px;background: hotpink;">
        <button @click="startMusic">
             播放
        </button>
        <button @click="endMusic">停止</button>
        <audio  ref="audioRefs" controls src="https://er-sycdn.kuwo.cn/25d37a44a438ec9bf513798caad0647e/65aa7a0f/resource/30106/trackmedia/M500000zRLcC1n2ZCU.mp3"></audio>
        <router-view></router-view>
    </div>
</div>
</template>
<script setup lang="ts">
import { ref, onMounted } from 'vue';
import {useRouter} from "vue-router";
const router  = useRouter()
const audioRefs = ref<HTMLElement>()

const startMusic = ()=>{
         let domElement = audioRefs.value as HTMLElement;
         domElement.play()
}
const endMusic = ()=>{
       let domElement = audioRefs.value as HTMLElement;
       domElement.pause()
       
}
onMounted(()=>{
      console.log(audioRefs)

})

文章来源:https://blog.csdn.net/2302_79777012/article/details/135714187
本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。