javascript - 如何在反应组件中引用外部Javascript文件
问题描述
这是我在 index.html 文件中引用的timeline.min.js 文件。请注意,我没有包含完整的代码。
function timeline(e, v) {
var g = [],
p = "Timeline:",
t = window.innerWidth,
i = void 0,
o = 0,
b = {
forceVerticalMode: { type: "integer", defaultValue: 600 },
horizontalStartPosition: { type: "string", acceptedValues: ["bottom", "top"], defaultValue: "top" },
mode: { type: "string", acceptedValues: ["horizontal", "vertical"], defaultValue: "vertical" },
moveItems: { type: "integer", defaultValue: 1 },
rtlMode: { type: "boolean", acceptedValues: [!0, !1], defaultValue: !1 },
startIndex: { type: "integer", defaultValue: 0 },
verticalStartPosition: { type: "string", acceptedValues: ["left", "right"], defaultValue: "left" },
verticalTrigger: { type: "string", defaultValue: "15%" },
visibleItems: { type: "integer", defaultValue: 3 },
};
function n(e, t, i) {
t.classList.add(i), e.parentNode.insertBefore(t, e), t.appendChild(e);
}
然后在同一个 Javascript 文件的末尾我有这个:
window.jQuery &&
(window.jQuery.fn.timeline = function (e) {
return timeline(this, e), this;
});
现在,在 index.html 文件中,有一个对时间线函数的引用,其中时间线模式更改为水平。
<script type="text/javascript" src="../src/assets/js/timeline/timeline.min.js"></script>
<script>
timeline(document.querySelectorAll('.timeline'), {
forceVerticalMode: 700,
mode: 'horizontal',
verticalStartPosition: 'left',
visibleItems: 7
});
console.log($("#ble").attr("class"));
</script>
现在,我想将所有这些集成到我的 React 组件中,因为当我运行代码时,时间线显示为垂直而不是水平。我的反应组件:返回(
2020 年 1 月 13 日
F2F
……解决方案
之前有人问过类似的问题。您可以查看以下链接。希望这可能会有所帮助。
https://stackoverflow.com/a/53396827/15004619
转到您的 index.html 文件并在那里导入脚本
<script type="text/javascript">
function fun(){
alert('Index.html is the main file to look at.');
}
</script>
在你的组件中使用window
对象。
componentWillMount() {
window.fun();
}
推荐阅读
- python - Python:如何从数据库创建饼图?
- node.js - 反对多次部署单体应用以模拟微服务的争论
- django - 在pytest中模拟Django包含标签
- reactjs - 带有 TypeScript 的 Redux Toolkit:如何正确键入异步 thunk 的返回值
- ios - 在可选 UIViewController 数组上操作时如何避免嵌套过多?
- laravel - 如何生成一个表(矩阵),其中一个表中的行和另一个表中的列?
- json - 使用 JSON 解码器读取 json 文件
- angular9 - Angular 9,如何从 NgbModal 返回值返回值到 canDeactivate
- shell - 有没有办法对列的一部分进行分组?
- oracle - 如何处理特殊字符在 UTF8 sqlldr ORACLE 中需要 2 个字节