chore: add helper to clear vditor cache

This commit is contained in:
Tim
2025-08-03 17:33:48 +08:00
parent 67910317e8
commit c3e377ca3c
4 changed files with 21 additions and 2 deletions

View File

@@ -18,7 +18,7 @@
</template>
<script>
import { ref, onMounted, computed, watch } from 'vue'
import { ref, onMounted, computed, watch, onUnmounted } from 'vue'
import { themeState } from '../utils/theme'
import {
createVditor,
@@ -26,6 +26,7 @@ import {
getPreviewTheme as getPreviewThemeUtil
} from '../utils/vditor'
import LoginOverlay from './LoginOverlay.vue'
import { clearVditorStorage } from '../utils/clearVditorStorage'
export default {
name: 'CommentEditor',
@@ -90,6 +91,10 @@ export default {
// applyTheme()
})
onUnmounted(() => {
clearVditorStorage()
})
watch(
() => props.loading,
val => {

View File

@@ -8,13 +8,14 @@
</template>
<script>
import { ref, onMounted, watch } from 'vue'
import { ref, onMounted, watch, onUnmounted } from 'vue'
import { themeState } from '../utils/theme'
import {
createVditor,
getEditorTheme as getEditorThemeUtil,
getPreviewTheme as getPreviewThemeUtil
} from '../utils/vditor'
import { clearVditorStorage } from '../utils/clearVditorStorage'
import { hatch } from 'ldrs'
hatch.register()
@@ -106,6 +107,10 @@ export default {
// applyTheme()
})
onUnmounted(() => {
clearVditorStorage()
})
return {}
}
}

View File

@@ -11,6 +11,7 @@ import { useToast } from 'vue-toastification'
import { checkToken, clearToken, isLogin } from './utils/auth'
import { initTheme } from './utils/theme'
import { loginWithGoogle } from './utils/google'
import { clearVditorStorage } from './utils/clearVditorStorage'
// Configurable API domain and port
// export const API_DOMAIN = 'http://127.0.0.1'
@@ -28,6 +29,7 @@ export const TWITTER_CLIENT_ID = 'ZTRTU05KSk9KTTJrTTdrVC1tc1E6MTpjaQ'
export const toast = useToast()
initTheme()
clearVditorStorage()
const app = createApp(App)
app.use(router)

View File

@@ -0,0 +1,7 @@
export function clearVditorStorage() {
Object.keys(localStorage).forEach(key => {
if (key.startsWith('vditoreditor-') || key === 'vditor') {
localStorage.removeItem(key)
}
})
}