Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refreshDeps: [spaceId], 依赖刷新问题, 如果spaceId是空我不想刷新,就要改成很麻烦的写法, 我希望加个为空不请求的条件 #254

Open
guorui999 opened this issue Dec 30, 2024 · 0 comments

Comments

@guorui999
Copy link

guorui999 commented Dec 30, 2024

我实际的代码
/**

  • 实时温湿度请求
    */
    export const useRequestTemHum = (spaceId: any) => {
    const { functionSetData } = storeToRefs(useConditionerStore());

const temHumData = ref([]);

const { data, run } = useRequest(apiTemHumAirQuality, {
pollingInterval: 5000,
manual: true
});

watch(spaceId, (val: any) => {
if (val) {
run(val);
}
});

watch(data, (val: any) => {
if (val?.data) {
temHumData.value = handleTemHumData(val.data, functionSetData.value);
}
});

onMounted(() => {
if (spaceId.value) {
run(spaceId.value);
}
});
return {
temHumData
};
};
我希望的代码
export const useRequestTemHum = (spaceId: any) => {
const { functionSetData } = storeToRefs(useConditionerStore(),{
refreshDeps: [spaceId], // 加个为空不请求的条件
});

const temHumData = ref([]);

const { data, run } = useRequest(apiTemHumAirQuality, {
pollingInterval: 5000,
manual: true
});

watch(data, (val: any) => {
if (val?.data) {
temHumData.value = handleTemHumData(val.data, functionSetData.value);
}
});

});
return {
temHumData
};
};

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant