遇到這個(gè)問(wèn)題時(shí)在網(wǎng)上查到了挺多答案,但似乎都不太好使,后來(lái)就自己寫(xiě)了個(gè)函數(shù),解決了一下這個(gè)問(wèn)題。
問(wèn)題:
screen = (
<ol className='tb'>
{items.result.map((item,index) =>
<li key={index} className='tb'>
<div className='main'>
<div className='contact-details'>
<center>
<h1>{item[0]}</h1>
<p>{item[1]}</p>
//想給href后面的url加變量
<a href ="http://localhost:63343/web-p/web-project/src/Result/Result.html?item=">show>>></a>
</center>
</div>
<div>
</div>
</div>
</li>
)}
</ol>)
解決:
replaceMessage(value){
var url;
url="http://localhost:63343/web-p/web-project/src/Result/Result.html?item="+value;
return url;
}
screen = (
<ol className='tb'>
{items.result.map((item,index) =>
<li key={index} className='tb'>
<div className='main'>
<div className='contact-details'>
<center>
<h1>{item[0]}</h1>
<p>{item[1]}</p>
<a href ={this.replaceMessage(item)}>show>>></a>
</center>
</div>
<div>
</div>
</div>
</li>
)}
</ol>)
效果:
網(wǎng)上找了一個(gè)免費(fèi)的淘寶接口,在另一個(gè)頁(yè)面獲取了一下數(shù)據(jù)做顯示

2019-02-26 10-54-15search.png

2019-02-26 10-54-50show.png