forked from project-trans/RLE-wiki
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
31 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} | ||
}); | ||
}); | ||
} | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters