【问题标题】:In ReactJs, I am having a basic issue?在 ReactJs 中,我遇到了一个基本问题?
【发布时间】:2020-09-11 10:17:15
【问题描述】:

我在 Reactjs 中使用的任何链接都显示评论。我正在使用 VSCode 编辑器。我是 React 的新手......这可能很愚蠢......对此感到抱歉。 我在这里分享两张图片。In the tag, src="{link...}" should be shown like this. But in my case (sharing another snapshot including error) it is only consider it as comment and it is not loading any images.

This is my code image...I am stuck with it...I want my code to work like the above code in image (1) shared

提前谢谢...

【问题讨论】:

    标签: reactjs webapi


    【解决方案1】:

    您必须使用反引号而不是单引号或双引号。

    原来如此

    <img src={`${var}`}
    

    而不是

    <img src={'${var}'}
    

    这是一个称为模板字符串的 javascript 功能。你可以在这里找到更多信息:https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Template_literals

    【讨论】:

    • 哦,我明白了...实际上与单引号不同...
    【解决方案2】:

    这是因为在 src 你使用单引号, 在 React 中不应该这样做。

    在 src 中使用类似这样的模板字符串,

    【讨论】:

    • 是的!这是一个不同的......我被困了大约 2 个小时......感谢您的帮助 ..@jarivak
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2019-05-15
    • 1970-01-01
    • 1970-01-01
    • 2020-04-29
    • 1970-01-01
    • 2021-04-20
    • 1970-01-01
    相关资源
    最近更新 更多