吉安感知网项目-前端
张含笑
2026-01-30 6c4bd2467bb6651c6edcf8a9741dcd4e9b1aa6d3
1
2
3
4
5
6
7
8
9
10
// 定义一个名为useRunOnce的自定义Hook,用于确保传递的函数只执行一次。
export const useRunOnce = (fn) => {
    const hasRun = ref(false)
    return (params = null) => {
        if (!hasRun.value) {
            fn(params)
            hasRun.value = true
        }
    }
};