4 回答

TA貢獻1817條經驗 獲得超14個贊
你不能像這樣合并2 if/else語句嗎?
if (condition1 === true && condition2 === true) {
LocalCall1()
} else {
ApiCall1()
}
編輯:
if (localStorage.getItem('constants') && JSON.parse(localStorage.getItem('constants')).version === serverVersion) {
const data = JSON.parse(localStorage.getItem('constants')).data;
} else {
const { response } = await apollo.query({ query });
if (!response) return {};
localStorage.setItem('constants', JSON.stringify({ version: serverVersion, data: response }));
}

TA貢獻1825條經驗 獲得超4個贊
二元的。。。
if(condition1 && condition2) res = 3;
if(!condition1 && condition2) res = 2;
if(condition1 && !condition2) res = 1;
if(!condition1 && !condition2) res = 0;
...然后,無論您想根據res做什么。

TA貢獻1799條經驗 獲得超8個贊
我知道這對你來說為時已晚,但它將來可能會幫助別人。
創建一個布爾標志,并在每次需要執行 ApiCall1() 時將其設置為 True。在外部 if 條件之外,如果此標志為 true,則調用 ApiCall1()。
添加回答
舉報