html元素下载为docx
- html-docx-js:htmlDocx.asBlob();
- file-saver: FileSaver.saveAs(htmlDocx.asBlob(), ‘title’)
例子:
let originHtml = '***';
let reg = /\<table/g;
let innerHtml = originHtml .replace(reg, function(result) {
return result + ' style="border: 1px solid #DDDDDD;border-collapse: collapse;" '
})
let htmlContent= `<!DOCTYPE html><html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
</head>
<style></style>
<body>
${innerHtml }
</body>
</html>`;
let converted = htmlDocx.asBlob(htmlContent);
FileSaver.saveAs(converted, `${title}.docx`);
Axios
- qs:qs.stringify() 序列化字符串,axios以表单方式提交时(Content-type: application/x-www-form-urlencoded),需要用它序列化入参
post(url, params, type, config) {
if (!params) {
params = {};
}
if (!config) {
config = {};
}
if (type == HttpConstant.FORM_DATA_REQ) {
params = qs.stringify(params);
}
return axios.post(url, params, config);
}
```