1、新建utils/index.js文件
// 防抖函数
export function debounce (fn, delay) {
let timer
return function () {
if (timer) {
clearTimeout(timer)
}
timer = setTimeout(() => {
fn()
}, delay)
}
}
2、在页面中使用
(1)在文件中引入
import { debounce } from '@/utils/index.js'
(2)在提交的函数使用
const dialogConfirm = debounce(()=>{
uni.showLoading({
title: '加载中...'
})
let t = state.time.substring(0, 10)+'T'+state.time.substring(11,19)+'.545Z'
Insert92a({
userId:uni.getStorageSync('idcard').id||'',
barCode:state.number,
sampleTime:t
}).then(res=>{
console.log(res,'==92');
if(res.code==200){
uni.navigateBack()
alertDialog.value.close()
uni.hideLoading()
}
}).finally(()=>{
uni.hideLoading()
})
},1500)