【问题标题】:How to use google map iframe embed code in react.js如何在 react.js 中使用谷歌地图 iframe 嵌入代码
【发布时间】:2020-04-25 12:53:15
【问题描述】:

我正在使用 react.js。我必须在我的联系我们页面上显示地图,所以我添加了从谷歌地图获得的 iframe 嵌入代码。我正在使用下面的代码。我没有使用任何 API。

import React from 'react';

const AddressMap=()=>{
  return(
    <div className="google-map-code">
        <iframe src="https://www.google.com/maps/embed?pb=!1m18!1m12!1m3!1d15282225.79979123!2d73.7250245393691!3d20.750301298393563!2m3!1f0!2f0!3f0!3m2!1i1024!2i768!4f13.1!3m3!1m2!1s0x30635ff06b92b791%3A0xd78c4fa1854213a6!2sIndia!5e0!3m2!1sen!2sin!4v1587818542745!5m2!1sen!2sin" width="600" height="450" frameborder="0" style="border:0;" allowfullscreen="" aria-hidden="false" tabindex="0"></iframe>

    </div>

  );
}
export{AddressMap}

我的页面出现错误

错误:style 属性需要从样式属性映射到 值,而不是字符串。例如 style={{marginRight: 间距 + 'em'}} 使用 JSX 时。

你能帮我解决这个问题吗?

【问题讨论】:

    标签: reactjs google-maps


    【解决方案1】:

    在 react 样式中需要一个对象。例如:style={{border:0}}

    import React from 'react';
     const AddressMap=()=>{
        return (
            <div className="google-map-code">
              <iframe src="https://www.google.com/maps/embed?pb=!1m18!1m12!1m3!1d15282225.79979123!2d73.7250245393691!3d20.750301298393563!2m3!1f0!2f0!3f0!3m2!1i1024!2i768!4f13.1!3m3!1m2!1s0x30635ff06b92b791%3A0xd78c4fa1854213a6!2sIndia!5e0!3m2!1sen!2sin!4v1587818542745!5m2!1sen!2sin" width="600" height="450" frameborder="0" style={{border:0}} allowfullscreen="" aria-hidden="false" tabindex="0"></iframe>
            </div>
        );
     }
     export{AddressMap}
    

    【讨论】:

    • 是的,它正在工作。我想知道你为什么使用 style={{border:0}}?
    • 在 React 中,内联样式不指定为字符串。相反,它们是用一个对象指定的,该对象的键是样式名称的驼峰式版本,其值是样式的值,通常是一个字符串。请参考:reactjs.org/docs/dom-elements.html#style
    • 如果您对答案感到满意,请投票并接受它作为答案。谢谢!
    • 感谢您的帮助。
    猜你喜欢
    • 2017-01-22
    • 2012-10-31
    • 1970-01-01
    • 2017-02-06
    • 1970-01-01
    • 1970-01-01
    • 2022-01-19
    • 2011-12-29
    • 2014-04-15
    相关资源
    最近更新 更多