简体   繁体   English

如何在React.js中导入外部JavaScript

[英]How to import external javascript in reactjs

I have a form where i need to ask the user to enter the location. 我有一个表格,我需要询问用户输入位置。 So I am using npm package react-geosuggest-plus , But i dont want to put <script src="https://maps.googleapis.com/maps/api/js?key=AIzaSyAjmry-FVO4U1mTEtvYnYHsBPfVmNicsZsw&libraries=places"></script> 所以我正在使用npm包react-geosuggest-plus ,但是我不想放<script src="https://maps.googleapis.com/maps/api/js?key=AIzaSyAjmry-FVO4U1mTEtvYnYHsBPfVmNicsZsw&libraries=places"></script>

this in the header section of html page, since i am using this library only in one file. 这是在html页的页眉部分,因为我仅在一个文件中使用此库。 I am using react-redux with webpack as codebase. 我正在将react-redux与webpack一起用作代码库。 Please let me know your suggestions. 请让我知道您的建议。

If you're using Webpack, you should add Babel. 如果您使用的是Webpack,则应添加Babel。 Then you can use ES6 importing: 然后,您可以使用ES6导入:

import 'react-geosuggest-plus'

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

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