Laravel的bootstrap-vue不能与nav collapse一起使用。

问题描述 投票:1回答:1

我试图让我的可折叠导航条在Laravel 7中的Vue + Bootstrap中工作, 但没有任何运气. 导航条显示没有任何问题, 但是当我调整大小并试图折叠它时, 按钮什么都不做, 也没有抛出任何错误.

我已经把bootstrap-vue导入到我的app.ts文件中, 它应该是被启用的, 但似乎没有.

应用程序.ts

import "./bootstrap";
import Vue from "vue";
import BootstrapVue from "bootstrap-vue"; //Importing

Vue.use(BootstrapVue); // Telling Vue to use this in whole application

// Require everything withing the /components directory as a Vue component
const files = require.context("./", true, /\.vue$/i);
files.keys().map(key =>
    Vue.component(
        key
            .split("/")
            .pop()
            ?.split(".")[0] ?? "",
        files(key).default
    )
);

new Vue({
    el: "#app"
});

导航条文件(main.blade.php)。

<!DOCTYPE html>
<html lang="{{ str_replace('_', '-', app()->getLocale()) }}">

<head>
    <meta charset="utf-8">
    <meta name="csrf-token"
          content="{{ csrf_token() }}">
    <meta name="viewport"
          content="width=device-width, initial-scale=1, shrink-to-fit=no">
    <title>nCoV Stats</title>
    <link href="{{ asset('css/app.css') }}"
          rel="stylesheet">
</head>

<body class="d-flex flex-column min-vh-100">
    <!-- Navbar -->
    <nav class="navbar navbar-expand-lg navbar-light bg-light">
        <a class="navbar-brand"
           href="#">Navbar</a>
        <button class="navbar-toggler"
                type="button"
                data-toggle="collapse"
                data-target="#navbarNav"
                aria-controls="navbarNav"
                aria-expanded="false"
                aria-label="Toggle navigation">
            <span class="navbar-toggler-icon"></span>
        </button>
        <div class="collapse navbar-collapse"
             id="navbarNav">
            <ul class="navbar-nav">
                <li class="nav-item active">
                    <a class="nav-link"
                       href="#">Home <span class="sr-only">(current)</span></a>
                </li>
                <li class="nav-item">
                    <a class="nav-link"
                       href="#">Features</a>
                </li>
                <li class="nav-item">
                    <a class="nav-link"
                       href="#">Pricing</a>
                </li>
                <li class="nav-item">
                    <a class="nav-link disabled"
                       href="#"
                       tabindex="-1"
                       aria-disabled="true">Disabled</a>
                </li>
            </ul>
        </div>
    </nav>

    <!-- Content -->
    <main id="app"
          class="wrapper flex-grow-1">
        @yield('content')
    </main>

    <!-- Footer -->
    <footer>
        <div class="container">
            <div class="row">
                <div class="col-8">
                    A Joe Scotto product.
                </div>
                <div class="col-4"></div>
            </div>
        </div>
    </footer>

    <script src="{{ asset('js/app.js') }}"></script>
</body>

</html>

根据我的理解,这应该是可以的,因为我是把它导入到了 app.ts

javascript laravel twitter-bootstrap vue.js bootstrap-vue
1个回答
3
投票

我想这是因为你在你的标记中没有使用任何Bootstrap-Vue组件. 在你的情况下,导航条应该是这样的。

<b-navbar toggleable="lg" type="light" variant="light">
    <b-navbar-brand href="#">NavBar</b-navbar-brand>

    <b-navbar-toggle target="nav-collapse"></b-navbar-toggle>

    <b-collapse id="nav-collapse" is-nav>
      <b-navbar-nav>
        <b-nav-item href="#">Home</b-nav-item>
        <b-nav-item href="#">Features</b-nav-item>
        <b-nav-item href="#">Pricing</b-nav-item>
      </b-navbar-nav>
    </b-collapse>
  </b-navbar>

你可以找到更多关于导航条组件的信息: 此处

此外,像porloscerrosΨ提到的那样,你需要设置为 id=app 在任何 body 元素或创建一个 divid=app 其中包含你的(Bootstrap-Vue)组件。

© www.soinside.com 2019 - 2024. All rights reserved.