是否可以在 const 中使用动态变量?
Is it possible to use dynamic variables inside a const?
我觉得这是一个愚蠢的问题,但是否可以在以下代码中使用动态变量:
const [viewport, setViewport] = useState ({
latitude:-8.683895,
longitude:115.152307,
width:800,
height:440,
zoom:16
});
我需要动态的纬度和经度,所以如下所示:
const [viewport, setViewport] = useState ({
latitude:{varLatitude),
longitude:{varLongitude},
width:800,
height:440,
zoom:16
});
请问正确的做法是什么?
干杯!
您可以简单地定义不需要添加括号的变量:
const [viewport, setViewport] = useState ({
latitude:varLatitude,
longitude:varLongitude,
width:800,
height:440,
zoom:16
});
我觉得这是一个愚蠢的问题,但是否可以在以下代码中使用动态变量:
const [viewport, setViewport] = useState ({
latitude:-8.683895,
longitude:115.152307,
width:800,
height:440,
zoom:16
});
我需要动态的纬度和经度,所以如下所示:
const [viewport, setViewport] = useState ({
latitude:{varLatitude),
longitude:{varLongitude},
width:800,
height:440,
zoom:16
});
请问正确的做法是什么? 干杯!
您可以简单地定义不需要添加括号的变量:
const [viewport, setViewport] = useState ({
latitude:varLatitude,
longitude:varLongitude,
width:800,
height:440,
zoom:16
});