当我将歌曲上传到数据库时,我将自己重定向到显示所有歌曲的主页,但我收到此错误:Cannot find module './my_song.mp3'尽管重新加载页面后一切正常,没有错误
从数据库中获取歌曲
async mounted() {
try {
const token = this.$store.getters["auth/getToken"];
const { result, ok } = await this.$store.dispatch("user/getData", {
data: ["songs"],
token,
});
let songs = [];
if (ok) {
songs = result.songs.map((song) => {
song.active = false;
// Думаю, что ошибка здесь
song.audio = new Audio(require(`@/uploads/${song.file}`).default);
song.currentTime = 0;
song.audio.volume = this.getVolume;
song.volume = this.getVolume;
return song;
});
}
this.$store.commit("setSongs", songs);
if (localStorage.getItem("volume")) {
this.$store.commit(
"setVolume",
JSON.parse(localStorage.getItem("volume"))
);
}
} catch (err) {
throw err;
}
},
应该是一个单独的异步函数。
重新启动后,歌曲会从缓存中取出,或者因为连接已经足够快地预热。并且在重载之前,脚本来不及直接在执行线程中接收,返回undefined。