[英]JavaScript curly braces not working embeded in string for jsx file in vs code
我正在開發一個簡單的react應用程序,我需要將一些JavaScript插入到img標簽中的url
react
JavaScript
img
url
props.monster.id 應該返回一個 int 用於 url。 但是它不起作用。 此外,js 也沒有像在 vs 代碼中那樣顯示。 這就是我正在關注的教程中的外觀。
代碼輸入相同,所以我不確定我在這里做錯了什么。這是在一個jsx文件中。
jsx
使用反引號(``)來做那不是''
只需使用這個:
src={`https://robohash.org/${props.monster.id}?set=set2`}
你可以在這里閱讀更多關於它的信息
[英]JSX within curly braces
[英]Why doesn't a string prop need curly braces in a JSX element?
[英]Replace Curly Braces in string with a HTML span Node in JSX
[英]Angular curly braces not working, basic code
[英]JavaScript Regex curly braces
[英]Curly braces in Javascript
[英]Javascript and curly braces in URL?
[英]javascript $ followed by curly braces
[英]Render curly braces as plain text in React/JSX
[英]if and else if statement inside JSX curly braces
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.