简体   繁体   English

安可 Webpack Bootstrap4.5 导航栏不工作

[英]Encore Webpack Bootstrap4.5 navbar not working

I am trying to learn Symfony.我正在尝试学习 Symfony。 I am using bootstrap to style my page.我正在使用引导程序来设置页面样式。 When i add this link <script src="https://cdn.jsdelivr.net/npm/bootstrap@5.0.0-beta1/dist/js/bootstrap.bundle.min.js" integrity="sha384-ygbV9kiqUc6oa4msXn9868pTtWMgiQaeYH7/t7LECLbyPA2x65Kgf80OJFdroafW" crossorigin="anonymous"></script> in my base.html.twig the navbar works fine.当我添加此链接<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.0.0-beta1/dist/js/bootstrap.bundle.min.js" integrity="sha384-ygbV9kiqUc6oa4msXn9868pTtWMgiQaeYH7/t7LECLbyPA2x65Kgf80OJFdroafW" crossorigin="anonymous"></script>在我的 base.html.twig 导航栏工作正常。 But when i used npm install jquery and used {{ encore_entry_script_tags('app') }} my navbar doesnt work anymore.但是当我使用 npm 安装 jquery 并使用{{ encore_entry_script_tags('app') }}我的导航栏不再工作。 It may be useful to know that i can see the bootstrap theme on the screen so i think that the scss part is working.知道我可以在屏幕上看到引导主题可能很有用,所以我认为 scss 部分正在工作。

Here is my app.js file这是我的 app.js 文件

import './styles/app.scss';

import $ from 'jquery';

global.$ = global.jQuery = $;

import greet from './greet';
// start the Stimulus application
import './bootstrap';

import 'bootstrap/dist/js/bootstrap.min.js';
import 'bootstrap/dist/css/bootstrap.min.css';

$(document).ready(function() {
    $('body').prepend('<h1>'+greet('mj')+'</h1>');
});

The greet function is working and the message is showing.问候 function 正在工作并且正在显示消息。

webpack.config.js webpack.config.js

In this file, I used enableSassLoader() in order to activate Sass and autoProvidejQuery() in order to have access to jQuery as a global variable.在这个文件中,我使用 enableSassLoader() 来激活 Sass 和 autoProvidejQuery() 以便访问 jQuery 作为全局变量。

Do you have any idea what's wrong?你知道有什么问题吗? Thank you for helping me.感谢你们对我的帮助。

I found the solution for anyone having the same problem.我为任何有同样问题的人找到了解决方案。 I had Bootstrap 4.5 so i just did npm install bootstrap@next -D which installed bootstrap 5 and everything worked我有 Bootstrap 4.5,所以我只是做了npm install bootstrap@next -D安装了 bootstrap 5 并且一切正常

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM