简体   繁体   English

Laravel 6-Bootstrap 为什么 Popover 在没有错误的情况下不起作用?

[英]Laravel 6-Bootstrap Why Popover doesn't work while there is no error?

I am currently learning laravel via developing applications.我目前正在通过开发应用程序学习 Laravel。 I did quite a thing in backend but still having tough times when I encounter a front-end problem.我在后端做了很多事情,但在遇到前端问题时仍然很艰难。 I am using bootstrap scaffolding and want to create a form in 'popover'.我正在使用 bootstrap 脚手架并想在“popover”中创建一个表单。 I can do that later, now I just want to work this button out .我可以稍后再做,现在我只想解决这个按钮。 I use the popover which is shown in bootstrap site.我使用引导站点中显示的弹出窗口。 Popover Bootstrap I'm just putting a button in the page and want it to have a popover when clicked. Popover Bootstrap我只是在页面中放置一个按钮,并希望它在单击时有一个弹出窗口。

<button type="button" class="btn btn-secondary" data-container="body"
                        data-toggle="popover" data-placement="left"
                        data-content="Vivamus sagittis lacus vel augue laoreet rutrum faucibus.">
                        Popover on left

When I use the {{ asset('js/app.js') }} (I mean the local file in public/js/) I can't make it work.当我使用 {{ asset('js/app.js') }} (我的意思是 public/js/ 中的本地文件)时,我无法让它工作。 But when I use these cdn scripts:但是当我使用这些 cdn 脚本时:

<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.4.1/jquery.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.16.0/umd/popper.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/4.4.1/js/bootstrap.min.js"></script>

and also add this script the bottom of body when I use cdn:并在我使用 cdn 时将此脚本添加到正文的底部:

$(function () { $('[data-toggle="popover"]').popover()})

It works.有用。 But this can't be a solution I would like to continue using my inner files not the ones imported from cdn.但这不是一个解决方案,我想继续使用我的内部文件而不是从 cdn 导入的文件。 According to my readings and observations, in app.js these scripts/functions are already included.根据我的阅读和观察,在 app.js 中已经包含了这些脚本/函数。 Only showing the path of app.js as stated above in blade file, should be enough in that case.在这种情况下,只在刀片文件中显示上述 app.js 的路径就足够了。 (I run 'npm install popper.js --save' also). (我也运行'npm install popper.js --save')。 I would like to have a way to work this button out with internal js files.我想有办法用内部 js 文件解决这个按钮。

Extra: When I type 'Popper' on console it responds me the following code line.额外:当我在控制台上输入“Popper”时,它会响应我下面的代码行。 So as I understand, it is defined.所以据我所知,它是定义的。

Popper(reference, popper) {
var _this = this;
var options = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};
classCallCheck(this, Popper);
this.scheduleUpdate…

Thanks in advance.提前致谢。

Edit a year later: I continue web development and when I saw this topic in my history I got wonder and read.一年后编辑:我继续 Web 开发,当我在我的历史中看到这个主题时,我感到惊奇并阅读了。 I can imagine the problem when I see the issue and the reason that it didn't work back then is jquery needs to be imported or required before both popper.js and bootstrap.当我看到问题时,我可以想象这个问题,当时它没有工作的原因是需要在 popper.js 和 bootstrap 之前导入或需要 jquery。 I should've understood that after inserting CDNs tho(by just looking the order).我应该明白在插入 CDN 之后(通过查看顺序)。 Text below belongs to a year ago and doesn't have any meaningful explanation.下面的文字是一年前的,没有任何有意义的解释。

Okay problem is solved in a very interesting way that I don't understand.好吧,问题以一种我不明白的非常有趣的方式解决了。 Please share your comments if you have idea still.如果您还有想法,请分享您的意见。 I deleted all cdn scripts, added window.Jquery = require('jquery');我删除了所有 cdn 脚本,添加了window.Jquery = require('jquery'); to resources/js/bootstrap.js file & kept $(function () { $('[data-toggle="popover"]').popover()}) script under .资源/ JS / bootstrap.js文件&保持$(function () { $('[data-toggle="popover"]').popover()})下的脚本。 Than I run npm run dev , after that it worked.比我运行npm run dev之后,它起作用了。 It made no sense to me because there is a codeline in same file which includes jquery as I understand: try{ window.Popper = require('popper.js').default; window.$ = window.jQuery = require('jquery'); require('bootstrap');}..这对我来说毫无意义,因为在同一个文件中有一个代码行,其中包含我理解的 jquery: try{ window.Popper = require('popper.js').default; window.$ = window.jQuery = require('jquery'); require('bootstrap');}.. try{ window.Popper = require('popper.js').default; window.$ = window.jQuery = require('jquery'); require('bootstrap');}.. try{ window.Popper = require('popper.js').default; window.$ = window.jQuery = require('jquery'); require('bootstrap');}.. After this I deleted the line which I added at the start window.Jquery = require('jquery'); try{ window.Popper = require('popper.js').default; window.$ = window.jQuery = require('jquery'); require('bootstrap');}..之后我删除了我在开始window.Jquery = require('jquery');添加的行window.Jquery = require('jquery'); and run npm run dev again, and it is still working.并再次运行npm run dev ,它仍然有效。 Now there is two things that I can think of: first;现在我能想到两件事:第一; Once I added window.Jquery = require('jquery');一旦我添加了window.Jquery = require('jquery'); and started npm run dev did something to one of my files and erasing that line doesn't matter now, or nothing special happenning here I just did something reaaaly wrong before opennig this topic.并开始npm run dev对我的一个文件做了一些事情,现在擦除该行并不重要,或者这里没有发生任何特别的事情我只是在打开这个主题之前做了一些非常错误的事情。 Thanks.谢谢。

Do you have window.Popper = require('popper.js').default;你有window.Popper = require('popper.js').default; in your resources/js/bootstrap.js or in resources/js/app.js file?在您的resources/js/bootstrap.jsresources/js/app.js文件中?

Maybe you could post the code from your bootstrap and app js files?也许您可以从引导程序和应用程序 js 文件中发布代码?

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

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