[英]sidebar not collapsing inside vue.js #app element (sb-admin-2)
so I have laravel project with sb-admin-2 and Vue.js所以我有一个带有 sb-admin-2 和 Vue.js 的 laravel 项目
as you can see when I'm using #app element in blade view for the whole HTML page then the sb-admin-2 sidebar not collapsing.正如您所看到的,当我在整个 HTML 页面的刀片视图中使用 #app 元素时,sb-admin-2 侧边栏不会折叠。
***NOTE*** this code is NOT working -> sidebar inside #app
{{-- this #app is for optional pages that using vue.js --}}
<div id="app"> ***NOTICE*************
<div id="wrapper">
<div id="content-wrapper" class="d-flex flex-column">
<div id="content">
<!-- Topbar -->
<nav class="navbar navbar-expand navbar-light bg-white topbar mb-4 static-top shadow">
<!-- Sidebar Toggle (Topbar) --> ***NOTICE****************
<button id="sidebarToggleTop" class="btn btn-link d-md-none rounded-circle mr-3">
<i class="fa fa-bars"></i>
</button>
</nav>
<!-- End of Topbar -->
@yield('content')
</div>
<!-- End of Main Content -->
</div>
<!-- End of Content Wrapper -->
</div>
<!-- End of Page Wrapper -->
</div>
{{-- end of #app element --}}
<!-- Bootstrap core JavaScript-->
<script src="{{ asset('js/admin/vendor/jquery/jquery.min.js') }}"></script>
<script src="{{ asset('js/admin/vendor/bootstrap/js/bootstrap.bundle.min.js') }}"></script>
<!-- Core plugin JavaScript-->
<script src="{{ asset('js/admin/vendor/jquery-easing/jquery.easing.min.js') }}"></script>
<!-- Custom scripts for all pages-->
<script src="{{ asset('js/admin/js/sb-admin-2.min.js') }}"></script>
<!-- Page level plugins -->
<script src="{{ asset('js/admin/vendor/chart.js/Chart.min.js') }}"></script>
<!-- vue.js -->
<script src="{{ asset('js/app.js') }}"></script>
but when I use it on lower level that's not include the sidebar toggler it's working again.但是当我在不包括侧边栏切换器的较低级别上使用它时,它又可以正常工作了。
***NOTE*** this code is working -> sidebar is NOT inside #app
{{-- this #app is for optional pages that using vue.js --}}
<div id="wrapper">
<div id="content-wrapper" class="d-flex flex-column">
<div id="content">
<!-- Topbar -->
<nav class="navbar navbar-expand navbar-light bg-white topbar mb-4 static-top shadow">
<!-- Sidebar Toggle (Topbar) --> ***NOTICE********************
<button id="sidebarToggleTop" class="btn btn-link d-md-none rounded-circle mr-3">
<i class="fa fa-bars"></i>
</button>
</nav>
<!-- End of Topbar -->
<div id="app"> ***NOTICE***********************
@yield('content')
</div>
{{-- end of #app element --}}
</div>
<!-- End of Main Content -->
</div>
<!-- End of Content Wrapper -->
</div>
<!-- End of Page Wrapper -->
<!-- Bootstrap core JavaScript-->
<script src="{{ asset('js/admin/vendor/jquery/jquery.min.js') }}"></script>
<script src="{{ asset('js/admin/vendor/bootstrap/js/bootstrap.bundle.min.js') }}"></script>
<!-- Core plugin JavaScript-->
<script src="{{ asset('js/admin/vendor/jquery-easing/jquery.easing.min.js') }}"></script>
<!-- Custom scripts for all pages-->
<script src="{{ asset('js/admin/js/sb-admin-2.min.js') }}"></script>
<!-- Page level plugins -->
<script src="{{ asset('js/admin/vendor/chart.js/Chart.min.js') }}"></script>
<!-- vue.js -->
<script src="{{ asset('js/app.js') }}"></script>
there are no errors no warning on loading the page or clicking the sidebar toggler.加载页面或单击侧边栏切换器时没有错误没有警告。
when the sidebar toggler is inside the vue.js #app, jquery(sb-admin-2) doesn't know any click event on this button exists.当侧边栏切换器位于 vue.js #app 中时,jquery(sb-admin-2) 不知道此按钮上存在任何点击事件。
this is my laravel bootstrap.js file:这是我的 laravel bootstrap.js 文件:
window._ = require('lodash');
window.axios = require('axios');
window.axios.defaults.headers.common['X-Requested-With'] = 'XMLHttpRequest';
this is my laravel app.js source file:这是我的 laravel app.js 源文件:
require('./bootstrap');
window.Vue = require('vue');
Vue.component('branches-component', require('./components/BranchesComponent.vue').default);
const app = new Vue({
el: '#app',
});
only when I remove vue.js from app.js then button works again.只有当我从 app.js 中删除 vue.js 时,按钮才会再次工作。
I finally found the answer.我终于找到了答案。
the problem was loading Vue javascript files after jquery and sb-admin-2 so the DOM wasn't rendered for jquery or something like that:问题是在 jquery 和 sb-admin-2 之后加载 Vue javascript 文件,因此没有为 jquery 或类似的东西呈现 DOM:
the correct way of including scripts was to import Vue first and then jquery, admin-sb-2, etc...包含脚本的正确方法是先导入 Vue ,然后导入jquery、admin-sb-2 等...
<!-- Vue.js should first-->
<script src="{{ asset('js/app.js') }}"></script>
<!-- jquery and admin-sb-2 , etc... -->
<script src="{{ asset('js/admin/vendor/jquery/jquery.min.js') }}"></script>
<script src="{{ asset('js/admin/vendor/bootstrap/js/bootstrap.bundle.min.js') }}"></script>
<script src="{{ asset('js/admin/vendor/jquery-easing/jquery.easing.min.js') }}"></script>
<script src="{{ asset('js/admin/js/sb-admin-2.min.js') }}"></script>
<script src="{{ asset('js/admin/vendor/chart.js/Chart.min.js') }}"></script>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.