将const添加到字符串?

时间:2018-04-23 09:32:53

标签: javascript

我刚开始学习React Native就遇到了问题。

我从我的服务器获取一个php文件,需要在URL中添加一个ID参数。 ID参数保存在const。

如何将我的const添加到fetch url的末尾?

const Round = 1;

return fetch('http://myurl/data.php?ID=')

3 个答案:

答案 0 :(得分:2)

您只需要连接Round变量。

const Round = 1;
return fetch('http://myurl/data.php?ID='+Round);

您也可以使用Template literals

return fetch(`http://myurl/data.php?ID=${Round}`);

答案 1 :(得分:1)

使用template literals

const round = 1;
return fetch(`http://myurl/data.php?ID=${round}`);

注意:常规变量应该具有小写名称。

答案 2 :(得分:0)

将const变量放在最后

例如

const Round = 1;

return fetch('http://myurl/data.php?ID='+Round)
相关问题