21 lines
374 B
JavaScript
21 lines
374 B
JavaScript
import { ref, onBeforeUpdate } from "vue";
|
|
function useRefs() {
|
|
const refs = ref([]);
|
|
const cache = [];
|
|
onBeforeUpdate(() => {
|
|
refs.value = [];
|
|
});
|
|
const setRefs = (index) => {
|
|
if (!cache[index]) {
|
|
cache[index] = (el) => {
|
|
refs.value[index] = el;
|
|
};
|
|
}
|
|
return cache[index];
|
|
};
|
|
return [refs, setRefs];
|
|
}
|
|
export {
|
|
useRefs
|
|
};
|