解决前端vue打包之后,在没有登录的情况下能访问静态资源

这里的静态资源在这里插入图片描述
显示的内容在这里插入图片描述
解决方法:
(1)通过请求接口返回数据流,前端在进行转换,然后在进行下载、
在这里插入图片描述

 let type = ""
            if (activeTabName == 'cross') {
                type = 2
            } else {
                type = 1
            }
            getAnalysis(type).then(res => {
                let blob = new Blob([res.data], {
                    type: `application/msword` //word文档为msword,pdf文档为pdf
                });
                let docxSrc = URL.createObjectURL(blob);
                let docxName = this.analysisRecord.name + '.docx' //导出文件的名字
                this.title = this.analysisRecord.name
                // 读取并获得模板文件的二进制内容
                let that = this
                JSZipUtils.getBinaryContent(docxSrc, function (error, content) {
                    // docxSrc是模板。我们在导出的时候,会根据此模板来导出对应的数据
                    // 抛出异常
                    if (error) {
                        throw error
                    }

                    const imageOpts = {
                        centered: false,
                        getImage(tag) {
                            return base64DataURLToArrayBuffer(tag)
                        },
                        getSize(img, tagValue, tagName) {
                            return [950, 300]
                        }
                    }
                    // 创建一个PizZip实例,内容为模板的内容
                    let zip = new PizZip(content)
                    const imageModule = new ImageModule(imageOpts)
                    const doc = new docxtemplater().loadZip(zip).attachModule(imageModule).compile()

                    // 设置模板变量的值
                    doc.setData({
                        title: that.title,
                        questionReportItems: that.questionReportItems
                    })

                    try {
                        // 用模板变量的值替换所有模板变量
                        doc.render()
                    } catch (error) {
                        // 抛出异常
                        let e = {
                            message: error.message,
                            name: error.name,
                            stack: error.stack,
                            properties: error.properties
                        }
                        console.log(JSON.stringify({
                            error: e
                        }))
                        throw error
                    }

                    // 生成一个代表docxtemplater对象的zip文件(不是一个真实的文件,而是在内存中的表示)
                    let out = doc.getZip().generate({
                        type: 'blob',
                        mimeType: 'application/vnd.openxmlformats-officedocument.wordprocessingml.document'
                    })
                    // 将目标文件对象保存为目标类型的文件,并命名
                    saveAs(out, docxName)
                })
            })


主要代码

 let blob = new Blob([res.data], {
  type: `application/msword` //word文档为msword,pdf文档为pdf
 });
 let docxSrc = URL.createObjectURL(blob);

Markdown将文本转换为 HTML。

注意:JSZipUtils用的插件:jszip-utils

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值