文章参考
问题描述
想利用腾讯地图的定位功能,发现这个功能需要引入单独的JS,但是这个JS文件是依赖地图主要的JS的,而我是使用的import ReactQMap from 'react-qmap';
这个控件来加载腾讯地图的,因此没有直接在index.html文件中引入文件,就需要在地图加载完成之后再引入’定位JS库’。
代码详解
const scriptObj = <Script
url="https://3gimg.qq.com/lightmap/components/geolocation/geolocation.min.js"
onCreate={this.handleScriptCreate.bind(this)}
onError={this.handleScriptError.bind(this)}
onLoad={this.handleScriptLoad.bind(this)}
/>
实际上 scriptObj 的render的值是null,因此可以把这个代码放到 render函数的任何地方,实际script标签是添加在
document.body.appendChild(script);
后面的