How can you update the content in real time when the src link of audio remains unchanged and the content of the link changes?

The

project was built using vue-cli family buckets, and I wrote a music playback tag on a page:

<audio id="audio" autoplay class="hide" :src="audioUrl"></audio>

then the js section:

playRecord() { //
    const audio = document.getElementById("audio");
    //this.recorder.play(audio);
    audio.src = this.GLOBAL.pro1_r_ip + "/sr/tmp/cache_readingcut.wav";
    audio.load();
},
uploadAudio() { //
    this.stopRecord();
    const record = this.recorder.getBlob();
    const t = this;
    let data;
    let reader = new window.FileReader();
    reader.readAsDataURL(record);
    reader.onloadend = function () {
        data = reader.result;
        t.$axios.post(t.GLOBAL.pro1_ip + "/readingcutupload", {
            file: data
        }).then(res => {
            if (res.data.result === 1) {
                t.success("");
            } else {
                t.error(res.data.msg);
            }
        })
    };
}

then comes the question:

what I do is a function of web page recording. After the user has recorded the audio file, the front end sends the audio file to the back end, then the back end stores it in the server, and then gives me a link to the stored address, and I directly play the audio file in that link.

now the backend gives a fixed storage address, but the contents will be refreshed in real time. When I upload a new audio, it will be refreshed into a newly uploaded audio file, but I use audio to read the linked audio every time I re-record it. The words I listen to online with headphones are the same audio and are not updated in real time, but the real audio file is really updated in real time after downloading and testing. Tried two methods:

one is the .load () method to overload the audio, but has no effect
the second is to delete the audio tag every time you re-record, and then re-insert a new audio tag after the recording is completed, but it has no effect

would like to ask you if there is a good solution?

-Segmentation Line-
I"m afraid what I"m saying is too cumbersome and a little difficult to understand. To put it simply and roughly, audio"s src uses the same link, but the music in the link changes dynamically, but the headphones on the web page always listen to the same song. How to solve this problem?


feels like a cache problem.
since the get request is automatically sent using audio's src, the no-cache request header cannot be set, so dynamic parameters are used to prevent caching.
for example, your link is https://www.aaa.com/bbb/ccc

.

then just add a different parameter each time you need to get it. https://www.aaa.com/bbb/ccc?r.
can be randomly numbered or incremented, as long as it is different.


is right. Just add a random number after src each time, such as the timestamp / sr/tmp/cache_readingcut.wav?t=$ {new Date (). GetTime ()}


. You can also consider dropping this node remove and then append it.


is actually cached, and the content of audio is cached by the browser. Url does not change the case, do not download again, in order to save bandwidth. You can add a hasc value to solve the problem, and you can add a calculation attribute to automatically add a timestamp, such as:

html:
<audio id="audio" autoplay class="hide" :src="url"></audio>

js:
computed: {
  url() {
    return this.audioUrl + '?' + new Date().getTime();
  }
}
If the

link remains unchanged, the address will be cached and the address will be time stamped

.
Menu