遇到一个需求是这样要求的把word文档的内容渲染在弹窗里展示
最开始思路跑偏了,一直在找识别world或者pdf文件的开源库,合适的库找到了,但是遇到了棘手的问题,因为我们的项目用的技术栈是vue3 vite解析不了word文件 百度了一下让加
build: {
assetsInclude: ['**/*.docx'], // 添加这一行
},
但是还是不行,一直报错[plugin:vite:import-analysis] Failed to parse source for import analysis because the content contains invalid JS syntax. You may need to install appropriate plugins to handle the .docx file format, or if it's an asset, add "**/*.docx" to assetsInclude in your configuration. /Users/user/workspace/chemball/yidu-cloud/frontend/src/assets/agreement/mock1.docx:2:106
后来转变了思路 可以用wps把word转成html文件 也可以保持原来的格式与样式 然后前端用v-html渲染,但是呢又遇到了问题,还是解析不了html文件,不过尝试了一下加一个?raw就可以啦
// ?raw 是一个查询参数(query parameter),它告诉构建工具(如 Vite)
// 以原始形式加载文件内容,而不是尝试将文件解析为 JavaScript 模块
import serviceAgreementDoc from "@/assets/agreement/serviceAgreement.html?raw";
import privacyPolicyDoc from "@/assets/agreement/privacyPolicy.html?raw";