我在vuejs中内置了一个dapp,它具有以下功能:
export function useBalanceRefetch() {
const userStore = useUserStore();
const fetchBalance = (address: string, currency: string) => {
const fetcher = currency === 'eth' ? fetchEthBalance : fetchArbBalance;
fetcher(address).then(balance => {
if (balance) {
userStore[currency === 'eth' ? 'balanceEth' : 'balanceArb'] = balance;
}
});
};
return { fetchBalance };
}
一切正常,但我需要添加另一个令牌。
我尝试了以下方法:
export function useBalanceRefetch() {
const userStore = useUserStore();
const fetchBalance = (address: string, currency: string) => {
const fetcher = currency === 'eth' ? fetchEthBalance ? fetchUsdtBalance : fetchArbBalance;
fetcher(address).then(balance => {
if (balance) {
userStore[currency === 'eth' ? 'balanceEth' ? 'balanceUsdt' : 'balanceArb'] = balance;
}
});
};
return { fetchBalance };
}
但它给了我一个错误:
const fetcher = currency === 'eth' ? fetchEthBalance ? fetchUsdtBalance : fetchArbBalance;
以及:
userStore[currency === 'eth' ? 'balanceEth' ? 'balanceUsdt' : 'balanceArb'] = balance;
任何帮助将是伟大的...我试图找出它没有成功。
1条答案
按热度按时间sy5wg1nm1#
三元意味着涉及三个部分。
?
value_if_true:
value_if_false你可以绕过嵌套更多三元表达式的障碍,但我推荐用有限的方式: