Поппер не загружается до начальной загрузки в Visual Studio 2017 ASP.NET MVC - PullRequest
0 голосов
/ 26 февраля 2019

Я пытаюсь реализовать всплывающие окна, но похоже, что poppers.js не хочет загружаться до bootstrap.js.Я пытался поместить пакет перед загрузкой, но он не хочет загружаться.BundleConfig:

public static void RegisterBundles(BundleCollection bundles)
{
    bundles.Add(new ScriptBundle("~/bundles/jquery").Include(
                "~/Scripts/jquery-{version}.js"));

    bundles.Add(new ScriptBundle("~/bundles/jqueryval").Include(
                "~/Scripts/jquery.validate*"));

    // Use the development version of Modernizr to develop with and learn from. Then, when you're
    // ready for production, use the build tool at https://modernizr.com to pick only the tests you need.
    bundles.Add(new ScriptBundle("~/bundles/modernizr").Include(
                "~/Scripts/modernizr-*"));

    bundles.Add(new ScriptBundle("~/bundles/popper").Include(
              "~/Scripts/popper.js"
              ));

    bundles.Add(new ScriptBundle("~/bundles/bootstrap").Include(
              "~/Scripts/bootstrap.js"
              ));

    bundles.Add(new StyleBundle("~/Content/css").Include(
              "~/Content/bootstrap.css",
              "~/Content/xbbcode.css",
              "~/Content/site.css"));


}

_Layout:

@Scripts.Render("~/bundles/popper")
@Scripts.Render("~/bundles/jquery")
@Scripts.Render("~/bundles/bootstrap")
@RenderSection("scripts", required: false)

Я все еще получаю эту ошибку:

jQuery.Deferred исключение: подсказки Bootstrap требуют Popper.js (https://popper.js.org/) Подсказка @ http://localhost:56609/Scripts/bootstrap.js:2836:15 Popover @ http://localhost:56609/Scripts/bootstrap.js:3509:14 _jQueryInterface / <@ <a href="http://localhost:56609/Scripts/bootstrap.js:3569:18" rel="nofollow noreferrer">http://localhost:56609/Scripts/bootstrap.js:3569:18 каждый @ http://localhost:56609/Scripts/jquery-3.3.1.js:354:10 каждый @ http://localhost:56609/Scripts/jquery-3.3.1.js:189:10 _jQueryInterface @ http://localhost:56609/Scripts/bootstrap.js:3559:14 load / http://localhost:56609/:299:46 mightThrow @ http://localhost:56609/Scripts/jquery-3.3.1.js:3534:21 resol / http://localhost:56609/Scripts/jquery-3.3.1.js:3602:12 undefined jquery-3.3.1.js: 3818: 3 TypeError: всплывающим подсказкам Bootstrap требуется Popper.js (https://popper.js.org/)

Ответы [ 2 ]

0 голосов
/ 29 мая 2019

Это занимало мою голову в течение приблизительно 30 минут, но мне удалось решить это.Все, что я сделал, это добавил UMD-версию popper.js и связал ее с bootstrap.js .

Что такое UMD

Шаблон UMD обычно пытается обеспечить совместимость с наиболее популярными загрузчиками сценариев того времени (например, RequireJS среди прочих).Во многих случаях он использует AMD в качестве базы со специальным корпусом, добавленным для поддержки совместимости с CommonJS.

Так что ваш BundleConfig.cs будет выглядеть следующим образом ...

            bundles.Add(new ScriptBundle("~/bundles/bootstrap").Include(
            "~/Scripts/umd/popper.js"
            "~/Scripts/bootstrap.js"));

Я также пытался связать его самостоятельно, и он работал.

        bundles.Add(new ScriptBundle("~/bundles/popper").Include(
                    "~/Scripts/umd/popper.js"));

Просто не забудьте добавить его в _Layout.cshtml .Кроме того, я думаю, что порядок имеет значение, поэтому попробуйте этот порядок.

    @Scripts.Render("~/bundles/jquery")
    @Scripts.Render("~/bundles/popper")
    @Scripts.Render("~/bundles/bootstrap")
    @RenderSection("scripts", required: false)

Итак * сначала 1030 * jQuery , popper , а затем bootstrap .Надеюсь, это поможет

0 голосов
/ 27 февраля 2019

Я решил, добавив bootstrap.bundle.js, который включает в себя popper.js внутри.

...