我正在尝试访问对象内部的对象,但是我很难弄清楚该怎么做。
{
id: "335f",
symbol: "fr",
name: "nom",
categories: [
"Langue"
],
localization: {
fr: "bonjour",
en: "hello",
},
我想在“本地化”内部访问“ fr”;
我设法对日志数据进行了本地化,但是我无法仅访问fr(它记录了所有内容)
const [data, setData] = useState({ coin: [] });
useEffect(() => {
const fetchData = async () => {
const result = await axios(url);
setData(result.data);
};
fetchData();
}, []);
console.log(data.localization)
答案 0 :(得分:0)
只需在异步上下文中移动console.log(data.localization)
,那么:
useEffect(() => {
const fetchData = async () => {
const result = await axios(url);
setData(result.data);
console.log(result.data.localization);
};
fetchData();
}, []);