reactjs 项目加载 javascript 个库并附加到 window 个对象
reactjs project load javascript libraries and attach to window object
我想向我的 reactJS 项目添加一些 javascript 库。
我通过在 index.html
的部分添加脚本标签来做到这一点
<script src="../src/components/reports/scripts/stimulsoft.reports.js"></script>
<script src="../src/components/reports/scripts/stimulsoft.viewer.js"></script>
库的用法如下:
class Viewer extends React.Component {
render() {
return <div id="viewerContent"></div>;
}
componentWillMount() {
var report = Stimulsoft.Report.StiReport.createNewReport();
report.loadFile("reports/Report.mrt");
var options = new Stimulsoft.Viewer.StiViewerOptions();
this.viewer = new Stimulsoft.Viewer.StiViewer(options, "StiViewer", false);
this.viewer.report = report;
}
componentDidMount() {
this.viewer.renderHtml("viewerContent");
}
}
但是我有这个错误:
这些是原始样本Stimulsoft Reports.JS and GitHub
根据问题下的评论,以及反应项目index.html文件中的指南如下:
//Notice the use of %PUBLIC_URL% in the tags above.
//It will be replaced with the URL of the `public` folder during the build.
//Only files inside the `public` folder can be referenced from the HTML.
我把scripts文件夹放到react工程的public文件夹下,修改src属性为新的源地址,问题就解决了
这段代码对我有用:
<script src="%PUBLIC_URL%/StimulSoft/scripts/stimulsoft.reports.js"></script>
<script src="%PUBLIC_URL%/StimulSoft/scripts/stimulsoft.viewer.js"></script>
我想向我的 reactJS 项目添加一些 javascript 库。
我通过在 index.html
的部分添加脚本标签来做到这一点<script src="../src/components/reports/scripts/stimulsoft.reports.js"></script>
<script src="../src/components/reports/scripts/stimulsoft.viewer.js"></script>
库的用法如下:
class Viewer extends React.Component {
render() {
return <div id="viewerContent"></div>;
}
componentWillMount() {
var report = Stimulsoft.Report.StiReport.createNewReport();
report.loadFile("reports/Report.mrt");
var options = new Stimulsoft.Viewer.StiViewerOptions();
this.viewer = new Stimulsoft.Viewer.StiViewer(options, "StiViewer", false);
this.viewer.report = report;
}
componentDidMount() {
this.viewer.renderHtml("viewerContent");
}
}
但是我有这个错误:
这些是原始样本Stimulsoft Reports.JS and GitHub
根据问题下的评论,以及反应项目index.html文件中的指南如下:
//Notice the use of %PUBLIC_URL% in the tags above.
//It will be replaced with the URL of the `public` folder during the build.
//Only files inside the `public` folder can be referenced from the HTML.
我把scripts文件夹放到react工程的public文件夹下,修改src属性为新的源地址,问题就解决了
这段代码对我有用:
<script src="%PUBLIC_URL%/StimulSoft/scripts/stimulsoft.reports.js"></script>
<script src="%PUBLIC_URL%/StimulSoft/scripts/stimulsoft.viewer.js"></script>