1

我想使用来自https://github.com/dpwilhelmsen/sb-admin-2-bootstrap-4的 SB Admin 2 模板

在我的 Laravel 5.7 / Vuejs 2.6 / Vuex 3.1/ Bootstrap 4.3 应用程序中,我为此采取了一些步骤:

因为它基于 metismenu 在控制台中我运行下一个命令:

npm install --save metismenu
npm i popper

npm audit fix

在 resources/js/app.js 我包含了 metismenu:

require('./bootstrap');


//require('popper');
/* If to uncomment line above in console I got lot of errors :
 WARNING in ./node_modules/popper/index.js 235:35-58
Critical dependency: the request of a dependency is an expression
 @ ./resources/js/app.js
 @ multi ./resources/js/app.js ./resources/sass/sb2/app.scss ./resources/sass/sb2/sb-admin-2.scss
 */

require('metismenu');

require('jquery');

window.Vue = require('vue');
...

在所有 vue 页面中使用的 resources/js/helpers/commonFuncs.js 中,我在方法处初始化菜单:

export function checkAuthorization(store, router) {
    // console.log("-11 checkAuthorization::")


    router.beforeEach((to, from, next) => {
        jQueryInit();

        next();


    ...

    function jQueryInit() {
    // alert( "jQueryInit"+(-55) )

    $(function () {
        // alert( "INSIDE::"+var_dump(-11) )
        $('#side-menu').metisMenu();
        console.log("Inside $('#side-menu')::")
        console.log($('#side-menu'))

    });

//Loads the correct sidebar on window load,
//collapses the sidebar on window resize.
// Sets the min-height of #page-wrapper to window size
    $(function () {
        var setupPage = function () {
            var topOffset = 50;

            console.log("++1 typeof window::")
            console.log(typeof window)
            console.log(window)

            var width = (window.innerWidth > 0) ? window.innerWidth : screen.width;
            if (width < 768) {
                $('div.navbar-collapse').removeClass('show');
                topOffset = 100; // 2-row-menu
            } else {
                $('div.navbar-collapse').addClass('show');
            }

            console.log("++2 typeof window::")
            console.log(typeof window)
            console.log(window)
            var height = ((window.innerHeight > 0) ? window.innerHeight : screen.height) - 1;
            height = height - topOffset;
            if (height < 1) height = 1;
            if (height > topOffset) {
                $("#page-wrapper").css("min-height", (height) + "px");
            }

        };
        // debugger


        $(window).bind("load resize", setupPage);

        var url = window.location;
        var element = $('ul.nav a').filter(function () {
            return this.href == url;
        }).addClass('active').parent();

        while (true) {
            if (element.is('li')) {
                element = element.parent().addClass('in').parent();
            } else {
                break;
            }
        }

        setupPage();
    });
    alert( "AFTER jQueryInit"+(-55) )
}

查看控制台我没有看到任何 JS 错误,并且看起来 window 是正确的 JS 对象。

我想那是 metismenu 初始化的最佳位置。

我没有手动附加任何 metisMenu.js / css 文件,如上所示

require('metismenu');

做好了。

但是我的页面布局被破坏了。您可以在http://hostels-tours.nilov-sergey-demo-apps.tk/admin/dashboard现场查看 请注意控制台输出:https ://imgur.com/a/xZ0EVNg

我添加了样式定义:

#wrapper {
  width: 100%;
  background-color: yellow;
  border: 2px dotted red;
}

确保应用了 resources/sass/sb2/sb-admin-2.scss 中的样式。出了什么问题,是否可以在 vue app metisMenu.js 中工作?

谢谢!

4

0 回答 0