1、定义播放按钮

在这里插入图片描述

 <el-button type="text" @click="handlePlay(scope.row)">播放</el-button> 

在这里插入图片描述

2、定义弹出层组件

    <el-dialog title="录音播放" :visible.sync="dialogVisible" width="20%" :before-close="stop">
      <template>
        <center>
          <audio
            :src="src"
            autoplay="autoplay"
            controls="controls"
            ref="audio"
          >Your browser does not support the audio element.</audio>
        </center>
      </template>
    </el-dialog>

3、JavaScript代码

<script>
  data() {
    return {
      src: "",
      dialogVisible: false,
    }
 
  methods: {
    //播放组件
    handlePlay(row) {
      this.src = row.filePath;
      this.play();
      });
    },
    //播放
    play() {
      this.dialogVisible = true;
      this.$refs.audio.play();
    },
    //音频暂停
    stop() {
      this.dialogVisible = false;
      this.$refs.audio.pause();
      this.$refs.audio.currentTime = 0;
    }
}
</script>
Logo

基于 Vue 的企业级 UI 组件库和中后台系统解决方案,为数万开发者服务。

更多推荐