0

I am using NuxtJS's AsyncData method to fetch a video file from an API and then return to the page as a file object.

Like so:

async AsyncData({$axios}){
    var user_video = null;
    try{
        var video = $axios.get("my awesome url");
        user_video = new File([video], "video.mp4",{type:"video/mp4"}); // <= this line
    }catch(error){
        console.log(error);
        console.log("no saved video");
    }

    return {user_video};
}

In in the server side console, it shows this error:

ReferenceError: File is not defined
    at asyncData (pages/send/video.js:155:11)
    at process._tickCallback (internal/process/next_tick.js:68:7)
no saved video

I've looked at other nuxtjs Content keys to use that may have something to do with creating a new File Object, but i have not found any. https://nuxtjs.org/api/context

I've tried searching for a similar error with using the File object in asyncdata, though I have not found anything.

Any suggestions?

Edit ---- Also To Add:

the URL I am fetching from brings to a download dialogue box in case this may be related.

4

1 回答 1

2

asyncData 在首次加载时在服务器上执行。在服务器上,节点中没有文件之类的东西。所以你不能在你的服务器代码上使用 File 。

您不应该使用 File 或不使用 asyncData 并使用挂载的钩子来获取和设置您的数据。

于 2019-07-19T20:44:11.647 回答