[英]How to reference external Javascript file inside react component
这是我在 index.html 文件中引用的时间线.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 文件中,有对时间线 function 的引用,其中时间线模式更改为水平。
<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 组件中,因为当我运行代码时,时间线显示为垂直而不是水平。
我的反应组件:返回(
F2F
……之前有人问过类似的问题。 您可以查看以下链接。 希望这可能会有所帮助。
https://stackoverflow.com/a/53396827/15004619
Go 给你 index.html 文件并在那里导入脚本
<script type="text/javascript">
function fun(){
alert('Index.html is the main file to look at.');
}
</script>
在您的组件中使用window
object。
componentWillMount() {
window.fun();
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.