Vue+iframe previews pdf, the page displays the pdf frame but the content is blank

Project scenario:

There is a page in the vue project that needs to preview the pdf, and switch the pdf display effect according to the list


Problem Description

After the backend sends back the file stream in blob format, the frontend receives and displays it. There is no error reported in the console, and responsesType: "blob" is also added. But only a blank box of the pdf is displayed on the page without content.
insert image description here

Front-end code:

<iframe :src=pdfViewUrl frameborder="0" height="900px" width="100%"></iframe>
axios({
    
    
	method:'get',
	responseType:'blob',
	url:'xxxxx',//后端接口地址
	}).then(({
    
    data})=>{
    
    
	let blob=new Blob([data],{
    
    type:'application/pdf'})
	this.pdfViewUrl=URL.createObjectURL(blob);
	})

solution:

After searching for a day or two, I finally saw that some big guys said that mocks might be introduced, because the project was taken over halfway, and I have no impression that mocks were introduced. I glanced at main.js and found that mocks were indeed introduced. . . . Speechless, who knows. . . .
The solution is to comment it out in main.js. . .

import '../mock' //注释掉

Guess you like

Origin blog.csdn.net/weixin_42567822/article/details/130556933