下载插件
html转word插件
| pnpm i --save html-docx-js-typescript |
复制
生成临时链接
复制
引入部分
| import * as htmlDocx from "html-docx-js-typescript"; |
| |
| import { saveAs } from 'file-saver' |
复制
代码部分
html部分,为要下载的部分用id做唯一标识
| <div :id="`mode-${chart.id}`"> |
| <pre><VueShowdown :markdown="chart.content"/></pre> |
| </div> |
复制
js部分
| |
| dom_options.value.forEach(async (item) => { |
| |
| const dom = document.querySelector(`#mode-${item}`) |
| |
| const convertedFile = htmlDocx.asBlob(dom?.outerHTML!); |
| |
| |
| const fileData = await convertedFile |
| saveAs((fileData as Blob), 'file.docx') |
| |
| }) |
复制