全局挂在防抖函数,防止重复提交数据
This commit is contained in:
parent
8ecfee1931
commit
7df3986a39
|
|
@ -27,6 +27,7 @@ import {
|
|||
selectDictLabels,
|
||||
handleTree,
|
||||
indexContinuation,
|
||||
debounce,
|
||||
} from '@/utils/ruoyi'
|
||||
// 分页组件
|
||||
import Pagination from '@/components/Pagination'
|
||||
|
|
@ -65,6 +66,7 @@ Vue.prototype.downloadJson = downloadJson
|
|||
Vue.prototype.handleTree = handleTree
|
||||
Vue.prototype.globalUrl = global_
|
||||
Vue.prototype.indexContinuation = indexContinuation
|
||||
Vue.prototype.debounce = debounce
|
||||
|
||||
// 全局组件挂载
|
||||
Vue.component('DictTag', DictTag)
|
||||
|
|
|
|||
|
|
@ -250,3 +250,18 @@ export function blobValidate(data) {
|
|||
export function indexContinuation(num, size) {
|
||||
return (num - 1) * size + 1
|
||||
}
|
||||
|
||||
export function debounce(fn, delay) {
|
||||
let timer = null
|
||||
return (...args) => {
|
||||
// 清除之前的定时器
|
||||
if (timer) {
|
||||
clearTimeout(timer)
|
||||
}
|
||||
|
||||
// 设置新的定时器,延迟执行函数
|
||||
timer = setTimeout(() => {
|
||||
fn.apply(...args) // 使用 `apply` 确保 `this` 指向 Vue 实例
|
||||
}, delay)
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue