The vue front end encapsulates a click-to-play audio component with a countdown

clipboard.png

<div class="speech-content">
   <div class="speech-info" @click="startSpeech"> 
       <i class="iconfont icon-speech" :class="speech?"icon-yuyin":"icon-yuyin""></i>
   </div>
   <audio :ref="audioRef" id="audio">
        <source :src="audioSrc" type="audio/mpeg" />
    </audio> 
   <span class="often-text">{{audioOftenText}}</span>
</div>

data(){
    return{
        isPlaying:false,  //
        speech:false,     //
        timeid:0       //
    }
}

//
getAudioList(){

}
//
startSpeech(){
    let self=this;
    if(!self.isPlaying){
        self.$refs.audioRef.play();
        self.isPlaying=true;
        self.speech=true;
        self.timeid= setInterval(function(){
            self.getProcess(); 
        },1000)
    }
    else{
        self.$refs.audioRef.pause();
        self.isPlaying=false;
        self.speech=false;
        clearInterval(self.timeid);
    }
},
//
getProcess(){
    let self=this;
    self.audioOften=parseInt(self.$refs.audioRef.duration-self.$refs.audioRef.currentTime);  //
    if(self.audioOften==0){    //isPlaying 
        self.isPlaying=false;
        self.speech=false;
    }
},
mounted(){
    let self=this;
    self.$nextTick(function(){
        setTimeout(()=>{
            self.getProcess();
        },1000);
    })
}

because each component needs a timer when it is clicked (to get the playback countdown of the corresponding component), and click on one of them, the other playback pauses and the timer pauses.
it"s OK to write one on the page, now you need to encapsulate the call, how to encapsulate it.

May.17,2022

component computed generates a 13-bit timestamp as a unique flag to perform your operation by judging the timestamp of the component instance

MySQL Query : SELECT * FROM `codeshelper`.`v9_news` WHERE status=99 AND catid='6' ORDER BY rand() LIMIT 5
MySQL Error : Disk full (/tmp/#sql-temptable-64f5-1ea5c9f-47b5b.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
MySQL Errno : 1021
Message : Disk full (/tmp/#sql-temptable-64f5-1ea5c9f-47b5b.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
Need Help?