Skip to content

Commit

Permalink
fix:pdf 导出
Browse files Browse the repository at this point in the history
  • Loading branch information
jinzhongjia committed Sep 26, 2024
1 parent 7111ccc commit 8d8b49e
Showing 1 changed file with 15 additions and 14 deletions.
29 changes: 15 additions & 14 deletions course/.vitepress/theme/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,24 +7,25 @@ import "./style/print.css";

import { h } from "vue";

// 保证在打印时所有的 details 都是展开的
window.addEventListener("beforeprint", function () {
document.querySelectorAll("details").forEach(function (details) {
details.setAttribute("open", "");
});
});

// 打印后重置 details 的展开状态
window.addEventListener("afterprint", function () {
document.querySelectorAll("details").forEach(function (details) {
details.removeAttribute("open");
});
});

export default {
...DefaultTheme,
enhanceApp(ctx: any) {
DefaultTheme.enhanceApp(ctx);
if (typeof window != "undefined") {
// 保证在打印时所有的 details 都是展开的
window.addEventListener("beforeprint", function () {
document.querySelectorAll("details").forEach(function (details) {
details.setAttribute("open", "");
});
});

// 打印后重置 details 的展开状态
window.addEventListener("afterprint", function () {
document.querySelectorAll("details").forEach(function (details) {
details.removeAttribute("open");
});
});
}
},
Layout() {
return h(DefaultTheme.Layout, null, {
Expand Down

0 comments on commit 8d8b49e

Please sign in to comment.