1.安装要用到的两个插件:html-docx-js-typescript、file-saver。
2.导入两个方法:
import { asBlob } from 'html-docx-js-typescript';
import { saveAs } from 'file-saver';
3.使用:
const html = ` <!DOCTYPE html><html lang="en"><head><meta charset="UTF-8"/><title>Document</title></head><body>......</body></html> `; asBlob(chuanshanjiaTemplate).then((data) => { saveAs(data, `文档名称.docx`); // save as docx file });