word_0">js生成word
下载依赖
javascript">npm install html-docx-js
引入
javascript">word">import htmlDocx word">from 'html-docx-js/dist/html-docx';
代码
javascript">//参数 html 文件名字 下载完执行回调函数
word">function html2word (html,fileName,callback){word">const converted = htmlDocx.asBlob(html);word">const link = document.createElement('a');link.href = URL.createObjectURL(converted);link.download = fileName?fileName+'.docx':'document.docx';link.click();callback&&callback()
}