Javascript 如何使用vuejs在新窗口中生成HTML?
我目前在表格生成中遇到了一个jsPDF for uniCode支持的问题,为了跳过这个问题,我使用了浏览器打印功能,只需创建一个新的html表格并将其显示为弹出窗口,然后调用Javascript 如何使用vuejs在新窗口中生成HTML?,javascript,vue.js,security,vuejs2,Javascript,Vue.js,Security,Vuejs2,我目前在表格生成中遇到了一个jsPDF for uniCode支持的问题,为了跳过这个问题,我使用了浏览器打印功能,只需创建一个新的html表格并将其显示为弹出窗口,然后调用popup\u window.print(),如下所示: //出口商 const temp = document.createElement("div"); temp.innerHTML = tableHtml( tableHead, tableBody, fileName
popup\u window.print()
,如下所示:
//出口商
const temp = document.createElement("div");
temp.innerHTML = tableHtml(
tableHead,
tableBody,
fileName
);
const popup_window: any = window.open(location.origin, fileName, "x=y");
popup_window.document.write(temp.innerHTML);
setTimeout(() => {
popup_window.print();
popup_window.close();
}, 1000);
//tableHtml.ts
const tableHtml = (
headers: string[],
records: GeneralOBJ[],
title: string,
direction = "rtl"
) => `<!DOCTYPE html>
<html>
<body>
<main id="main" style="direction: ${direction};">
<h1>${title}</h1>
<div class="app_table">
<table class="table">
<thead>
<tr>
${headers
.map(header => "<th class='col' dir='auto'>" + header + "</th>")
.join("")}
</tr>
</thead>
<tbody>
${records
.map(
record =>
"<tr>" +
Object.values(record)
.map(td => "<td dir='auto'>" + td + "</td>")
.join("") +
"</tr>"
)
.join("")}
</tbody>
</table>
</div>
</main>
</body>
</html>`;
const tableHtml=(
标题:字符串[],
记录:GeneralOBJ[],
标题:字符串,
方向=“rtl”
) => `
${title}
${headers
.map(标题=>“”+标题+“”)
.join(“”)
${记录
.地图(
记录=>
"" +
对象值(记录)
.map(td=>“”+td+“”)
.join(“”)+
""
)
.join(“”)
`;
它工作得很好,但正如您所知,在这里可能会出现诸如
xss
之类的安全问题。所以,我想使用vue生成这个html页面,然后将其添加为temp.innerHTML
,你知道怎么做吗?VueJS是一个单页应用程序库,使用它可以在一个html文件中呈现所有内容。可以在不同的html页面中创建两个或多个Vue实例,但必须进行设置,使它们共享相同的存储/数据
让它工作的一种方法可能是创建一个包含弹出内容的组件,然后在弹出html窗口上创建另一个Vue实例,并在那里装载组件。也许您可以在这里了解如何以编程方式创建组件实例
如果这是我的情况,我会先找到一个最简单的解决方法。如果问题是unicode支持,我会找到另一个库。关于pdf生成中的unicodes,请检查此项