繁体   English   中英

React 中的插值不能以这种方式工作,有人可以在这方面帮助我吗?

[英]Interpolation in React is not working this way can anybody please help me in this regards?

我正在尝试插值,这样

var sample = "test";
var result = 'this is just a ${sample}'; 
alert(result);                         

它不起作用,它只是在发出警报,这只是一个 ${sample},有人可以帮我解决这个问题吗? 谢谢

您需要使用反引号而不是引号(键盘上1的左侧)

var result = `this is just a ${sample}`; 

使用 ES5,它将是

var sample = "test";

var result = 'this is just a '+sample; 

alert(result);                             

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM