Skip to content

wachEffect 依赖更新项会一直重复请求 #252

@guorui999

Description

@guorui999

/**

  • 恒温、恒湿控制列表请求
    */
    export const useRequestControlTree = (spaceId: any, type = 'Temperature') => {
    const { data, run } = useRequest(apiGetControlTree, {
    manual: true,
    pollingInterval: 5000
    });

const controlTree = ref([]);
watch(data, (val: any) => {
if (val?.data) {
controlTree.value = val.data;
}
});

/**

  • 请求控制树
    */
    const requestControlTree = () => {
    spaceId.value &&
    run({
    devTypeKeys: type === 'Temperature' ? ['S014', 'S015', 'S016'] : ['S030'], // 'S014' | 'S015' | 'S016' | 'S030'
    spaceId: spaceId.value
    });
    };

watchEffect(() => {
if (spaceId.value) {
requestControlTree();
}
});

return {
controlTree,
requestControlTree
};
};
这样写会触发一直重复请求

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions