ant-design / ant-design-pro

👨🏻‍💻👩🏻‍💻 Use Ant Design like a Pro!
https://pro.ant.design
MIT License
36.54k stars 8.15k forks source link

🧐[问题] public/index.html 文件没有,那么类似百度地图的js怎么添加? #9297

Closed jacktang closed 3 years ago

jacktang commented 3 years ago

🧐 问题描述

项目需要使用百度地图,原来在index.html里面添加

<script type="text/javascript" src="http://api.map.baidu.com/api?v=2.0&ak=KEY"></script>

即可。现在 public/index.html 文件已经不存在。使用react hemlet 添加不成功。 (见示例代码)

💻 示例代码

import {BaiduMap} from 'react-baidu-maps';

const Index: React.FC = () => {
  return (
     <div>
      <Helmet>
        <title>领跑求职: 联接下一个优秀机会</title>
        <script type="text/javascript" src="http://api.map.baidu.com/api?v=2.0&ak=5RxhT8sogDv6N7hVgoz9AkKLAT2ynXbU"></script>
      </Helmet>
      {/* <div className={styles.lang} data-lang>
        {SelectLang && <SelectLang />}
      </div> */}
      <div style={{position: 'absolute', top: 0, left: 0, width: '100%', background: '#444', height: 'calc(100vh - 166px)'}}>
        <BaiduMap ref={mapRef} enableScrollWheelZoom mapContainer={<div style={{height: '100%'}}/>}>
          <NavigationControl
            type="small"
            anchor="top_right"
            offset={{width: 0, height: 1}}/>
        </BaiduMap>
      </div>
  </div>
)
}

错误信息

截屏2021-11-14 18 12 29

🚑 其他信息

chenshuai2144 commented 3 years ago

https://umijs.org/config#headscripts 用这个

jacktang commented 2 years ago

https://umijs.org/config#headscripts 用这个

能详细说下怎么配置吗?对umijs不是很熟悉

jacktang commented 2 years ago

已解决,在config.ts里面配置