Javascript 如何在URL中传递变量值?

Javascript 如何在URL中传递变量值?,javascript,html,reactjs,jsx,Javascript,Html,Reactjs,Jsx,我试图根据一些可变数据点击一个URL { this.state.countries.map((country, key) => { return <a key={country.iso2}> <img src="https://www.countryflags.io/{country.iso2}/shiny/24.png" /> </a>; }); } { this.state.countries.map((国家,键

我试图根据一些可变数据点击一个URL

{
  this.state.countries.map((country, key) => {
    return <a key={country.iso2}>
      <img src="https://www.countryflags.io/{country.iso2}/shiny/24.png" />
    </a>;
  });
}
{
this.state.countries.map((国家,键)=>{
返回
;
});
}
上述URL中的值{country.iso2}是动态的。 请帮助我正确设置URL的格式。

试试。注意使用
反勾选
$

<img src=`https://www.countryflags.io/${country.iso2}/shiny/24.png`/>

试试看。注意使用
反勾选
$

<img src=`https://www.countryflags.io/${country.iso2}/shiny/24.png`/>

你可以像这样做

{this.state.countries.map((country, key) => {
       return
           <a key={country.iso2}>
               <img src=`https://www.countryflags.io/${country.iso2}/shiny/24.png`/>
                                </a>
 })}
{this.state.countries.map((国家,键)=>{
返回
})}
你可以像这样做

{this.state.countries.map((country, key) => {
       return
           <a key={country.iso2}>
               <img src=`https://www.countryflags.io/${country.iso2}/shiny/24.png`/>
                                </a>
 })}
{this.state.countries.map((国家,键)=>{
返回
})}

使用反勾号和美元符号

{this.state.countries.map((country, key) => {
                            return
                                <a key={country.iso2}>
                                <img src=`https://www.countryflags.io/${country.iso2}/shiny/24.png`/>
                                </a>
 })}
{this.state.countries.map((国家,键)=>{
返回
})}

使用反勾号和美元符号

{this.state.countries.map((country, key) => {
                            return
                                <a key={country.iso2}>
                                <img src=`https://www.countryflags.io/${country.iso2}/shiny/24.png`/>
                                </a>
 })}
{this.state.countries.map((国家,键)=>{
返回
})}

正确的做法是使用


如果您的值是动态的,则使用
回勾
$

正确的做法是使用

<img src=`https://www.countryflags.io/${country.iso2}/shiny/24.png`/>

如果您的值是动态的,那么在使用jsx时使用
回勾
$

,您必须添加大括号,然后是模板文本,然后是由
${}
包围的变量,如下所示:

<img src=`https://www.countryflags.io/${country.iso2}/shiny/24.png`/>
let country={iso2:“au”};
ReactDOM.render(
,
根
);

在使用jsx时,必须先添加大括号,然后添加模板文本,然后添加被
${}
包围的变量,如下所示:

let country={iso2:“au”};
ReactDOM.render(
,
根
);