pref: debounce

This commit is contained in:
KUN1007 2023-08-24 23:59:37 +08:00
parent 958e734e85
commit 6f3829c36b
3 changed files with 20 additions and 5 deletions

View file

@ -12,6 +12,8 @@ import { useKUNGalgameEditStore } from '@/store/modules/edit'
import { storeToRefs } from 'pinia'
// xss
import DOMPurify from 'dompurify'
//
import { debounce } from '@/utils/debounce'
const topicData = storeToRefs(useKUNGalgameEditStore())
@ -70,11 +72,14 @@ onBeforeUnmount(() => {
//
const handleChange = (editor: IDomEditor) => {
editorRef.value = editor
//
setTimeout(() => {
//
const debouncedUpdateContent = debounce(() => {
// xss
topicData.content.value = DOMPurify.sanitize(editor.getHtml())
}, 1007)
//
debouncedUpdateContent()
//
textCount.value = editor.getText().trim().length
}

View file

@ -1,3 +1,6 @@
/*
*
*/
export type DebouncedFunction<T extends (...args: any[]) => any> = (
...args: Parameters<T>
) => void

View file

@ -9,6 +9,9 @@ import KUNGalgameFooter from '@/components/KUNGalgameFooter.vue'
import { useKUNGalgameEditStore } from '@/store/modules/edit'
import { storeToRefs } from 'pinia'
//
import { debounce } from '@/utils/debounce'
const topicData = storeToRefs(useKUNGalgameEditStore())
//
@ -34,10 +37,14 @@ const handelInput = () => {
return
}
//
setTimeout(() => {
//
const debouncedInput = debounce(() => {
// xss
topicData.title.value = topicTitle.value
}, 1007)
}, 300)
//
debouncedInput()
}
</script>