前端如何用vue将后端返回的html代码转成word文档并下载

前端如何用vue将后端返回的html代码转成word文档并下载,可以使用html-docx-js这个库。

首先安装该库:

npm install html-docx-js
 

然后在vue组件中引入该库

import htmlDocx from 'html-docx-js';

接着,将后端返回的html代码转成docx格式:

const html = '<html><body>Hello World!</body></html>';

const converted = htmlDocx.asBlob(html);

最后,将转换后的docx文件下载:

const link = document.createElement('a');

link.href = URL.createObjectURL(converted);

link.download = 'example.docx'; link.click();

猜你喜欢

转载自blog.csdn.net/weixin_60196946/article/details/130783923