媒体自动播放

<template>
<!--  <router-view/>-->
  <el-button ref="btnRef" @click="change">点击菜单</el-button>
  <audio controls autoplay ref="audioRef" >
    <source muted src="http://172.18.248.205/group1/M00/7A/39/rBL4zWSnqf6AKvn-AAhzU9tZ80k074.wav" type="audio/wav"/>
  </audio>
</template>

<script lang="ts" setup>
import {onMounted, ref, watch, watchEffect} from "vue";
const audioRef = ref();
const btnRef = ref();
const status = ref();

let play = function () {
  console.log("啥也不干...");
  watch(() => {
    console.log(status.value);
    if (status.value) {
      audioRef.value.play()
    }
  })
};

onMounted(() => {
  setTimeout(() => {
    status.value = 22;
  }, 5000);
})

const change = function () {
  play();
};



</script>
posted @ 2023-07-07 15:00  fight139  阅读(9)  评论(0编辑  收藏  举报