简体   繁体   English

ES6 模板文字中的 URL 插入

[英]Url insertion in ES6 Template literlals

I have a Json file containing many objects and I want to display them using the template literals syntax in ES6.我有一个包含许多对象的 Json 文件,我想使用 ES6 中的模板文字语法显示它们。 I need to display a set of images but cant passes any URL because it seems to delete the // of the address.我需要显示一组图像,但不能传递任何 URL,因为它似乎删除了地址的 //。 Else everything works perfectly.否则一切正常。

The problem seems to come from the innerHTML function because when I console log the variable containing the HTML code to be inserted the URL is written perfectly.问题似乎来自innerHTML函数,因为当我控制台日志包含要插入的HTML代码的变量时,URL写得很完美。

I would like to figure out how to fix this and display my images correctly我想弄清楚如何解决这个问题并正确显示我的图像

( the HTML inside the template literal is way longer, I just simplified it for here ) (模板文字中的 HTML 更长,我只是在这里简化了它)

 const resultat = document.querySelector('.master-wrapper'); //where the result appear

    const html = pokedex.map(pokedex => {
        return `
                <img src"  ${ pokedex.img } "></img>  //where the url is inserted
               `;
    }).join('')

    resultat.innerHTML += html;

您在这里缺少=符号,因此浏览器将其呈现为删除斜杠的单独属性。

<img src="  ${ pokedex.img } "></img>  //where the url is inserted

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM