修改样式与lint
This commit is contained in:
@@ -41,7 +41,7 @@
|
||||
* </template>
|
||||
* ```
|
||||
*/
|
||||
import { ref, watch } from 'vue'
|
||||
import { ref, watch, getCurrentInstance, onMounted } from 'vue'
|
||||
|
||||
// 定义各种选项
|
||||
const themes = [
|
||||
@@ -224,18 +224,34 @@ export function useTheme() {
|
||||
}
|
||||
}
|
||||
|
||||
// 确保在客户端时立即初始化
|
||||
// 确保在客户端时初始化
|
||||
if (import.meta.client) {
|
||||
// 立即初始化,避免闪烁
|
||||
initializeTheme()
|
||||
|
||||
// 确保在DOM准备好后再次应用
|
||||
onMounted(() => {
|
||||
applyThemeVariables()
|
||||
if (selectedThemeColor.value === 'custom') {
|
||||
applyCustomColor()
|
||||
const instance = getCurrentInstance()
|
||||
if (instance) {
|
||||
// 在组件 setup 上下文中,安全使用 onMounted
|
||||
onMounted(() => {
|
||||
applyThemeVariables()
|
||||
if (selectedThemeColor.value === 'custom') {
|
||||
applyCustomColor()
|
||||
}
|
||||
})
|
||||
} else {
|
||||
// 非组件上下文(如插件)中,等待文档就绪后应用
|
||||
const run = () => {
|
||||
applyThemeVariables()
|
||||
if (selectedThemeColor.value === 'custom') {
|
||||
applyCustomColor()
|
||||
}
|
||||
}
|
||||
})
|
||||
if (document.readyState === 'loading') {
|
||||
window.addEventListener('DOMContentLoaded', () => run(), { once: true })
|
||||
} else {
|
||||
run()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
const resetSettings = () => {
|
||||
|
Reference in New Issue
Block a user