后端返回文件流,前端如何请求并打开 --pdf

请求头需要加上
responseType: ‘blob’,

{
        responseType: 'blob',
        url: url,
        method: 'get',
    }

接到返回值后

.then((data) => {
                const blob = new Blob([data],{
                    type:'application/pdf'
                })
                let url = window.URL.createObjectURL(blob);
                window.open(url,"_blank")
            });

你可能感兴趣的:(前端,前端,pdf)