簡體   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