我的react应用程序中有一个jquery脚本offcanvas菜单。但是它只有在页面刷新后才会触发。
请在下面检查我的代码:
index.html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>App</title>
<!-- inject:css -->
<link rel="stylesheet" href="../public/css/style.css" />
<!-- To fix issue in multiple path parameters -->
<base href="/" />
<!-- endinject:css -->
<style>
a { cursor: pointer; }
.help-block { font-size: 12px; }
</style>
<script src="../public/vendors/node_modules/jquery/dist/jquery.min.js"></script>
<script src="../public/js/off-canvas.js"></script>
</head>
<body>
<div id="app"></div>
</body>
<!-- plugins:js -->
<script src="../public/vendors/node_modules/bootstrap/dist/js/bootstrap.min.js"></script>
<!-- endinject -->
</html>
offcanvas.js
(function($) {
'use strict';
$(function() {
$('[data-toggle="offcanvas"]').on("click", function () {
$('.sidebar-offcanvas').toggleClass('active')
});
});
})(jQuery);
我被困住了,不知道如何前进。任何帮助将不胜感激。谢谢!