Skip to content

Commit

Permalink
fix(theme): 修复搜索功能的标签闭合问题
Browse files Browse the repository at this point in the history
  • Loading branch information
Leetfs committed Sep 8, 2024
1 parent b455ea2 commit 11416f6
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 1 deletion.
30 changes: 30 additions & 0 deletions docs/.vitepress/enhanceApp.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
import { App, createApp, nextTick } from 'vue';
import SearchWithAria from '../../packages/vitepress-theme-project-trans/src/components/SearchWithAria.vue';

export default {
enhanceApp({ app, router }) {
// 全局注册组件
app.component('SearchWithAria', SearchWithAria);

// 每次路由更改时插入 SearchWithAria 组件
router.onAfterEach(() => {
nextTick(() => {
// 获取页面内容的容器
const appRoot = document.querySelector('.vp-content');

// 确保组件没有重复插入
if (appRoot && !appRoot.querySelector('.search-with-aria-container')) {
// 创建一个容器来放置 Vue 组件
const searchEl = document.createElement('div');
searchEl.classList.add('search-with-aria-container');

// 将新创建的容器插入到页面顶部或底部
appRoot.prepend(searchEl); // 使用 append 挂载到页面底部

// 使用 Vue 的实例化方法将 SearchWithAria 挂载到容器
createApp(SearchWithAria).mount(searchEl);
}
});
});
}
};
2 changes: 1 addition & 1 deletion docs/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -46,4 +46,4 @@ import HomeContent from '@project-trans/vitepress-theme-project-trans/components
:::

</HomeContent>
</SearchWithAria>
<SearchWithAria />

0 comments on commit 11416f6

Please sign in to comment.