let date;request({url: this.$route.query.url,method: 'get',responseType: 'blob',}).then(resp => {date = respthis.path = window.URL.createObjectURL(new Blob([resp], {type: "application/pdf"}))}).catch((e) => {//旧版本浏览器下的blob创建对象window.BlobBuilder = window.BlobBuilder ||window.WebKitBlobBuilder ||window.MozBlobBuilder ||window.MSBlobBuilder;if (e.name == 'TypeError' && window.BlobBuilder) {if (date) {BlobBuilder.append(date);this.path = URL.createObjectURL(new BlobBuilder().getBlob("application/pdf"))}} else {console.log("浏览器版本较低,暂不支持该文件类型预览");}}).finally(() => {window.URL.revokeObjectURL(this.path);})
responseType必须设置为blob
<iframe style="width: 100%;height: 500px" :src="path"></iframe>