Laravel 8中的导航栏下拉菜单无法正常工作
P粉460377540
P粉460377540 2023-12-16 11:55:20
0
1
669

我在 Laravel 8 中的导航栏遇到问题;具体来说,整个导航栏显示在视图上,但下拉菜单不起作用。

事实上,当我单击时,下拉菜单不会打开。

这是layout.blade.php

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <link rel="stylesheet" href="{{asset('css/app.css')}}">
    <title>Document</title>
</head>
<body>
    
    <x-navbar/>
    
    {{$slot}}

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

这是navbar.blade.php

<nav class="navbar navbar-expand-lg navbar-light bg-light">
  <div class="container-fluid">
    <a class="navbar-brand" href="#">Navbar</a>
    <button class="navbar-toggler" type="button" data-bs-toggle="collapse" data-bs-target="#navbarSupportedContent" aria-controls="navbarSupportedContent" aria-expanded="false" aria-label="Toggle navigation">
      <span class="navbar-toggler-icon"></span>
    </button>
    <div class="collapse navbar-collapse" id="navbarSupportedContent">
      <ul class="navbar-nav me-auto mb-2 mb-lg-0">
        <li class="nav-item">
          <a class="nav-link active" aria-current="page" href="#">Home</a>
        </li>
        <li class="nav-item">
          <a class="nav-link" href="#">Link</a>
        </li>
        <li class="nav-item dropdown">
          <a class="nav-link dropdown-toggle" href="#" id="navbarDropdown" role="button" data-bs-toggle="dropdown" aria-expanded="false">
            Dropdown
          </a>
          <ul class="dropdown-menu" aria-labelledby="navbarDropdown">
            <li><a class="dropdown-item" href="#">Action</a></li>
            <li><a class="dropdown-item" href="#">Another action</a></li>
            <li><hr class="dropdown-divider"></li>
            <li><a class="dropdown-item" href="#">Something else here</a></li>
          </ul>
        </li>
        <li class="nav-item">
          <a class="nav-link disabled">Disabled</a>
        </li>
      </ul>
      <form class="d-flex">
        <input class="form-control me-2" type="search" placeholder="Search" aria-label="Search">
        <button class="btn btn-outline-success" type="submit">Search</button>
      </form>
    </div>
  </div>
</nav>

而 home.blade.php 视图是:

<x-layout>
    <h1>Hello!!!</h1>
</x-layout>

P粉460377540
P粉460377540

全部回复(1)
P粉851401475

请尝试使用此方法,否则可能会出现拼写错误。

@include('inc.navbar')
//      @include('FOLDER_NAME.FILE_NAME')

还要检查文档! https://laravel.com/docs/9.x/blade#include-子视图

热门教程
更多>
最新下载
更多>
网站特效
网站源码
网站素材
前端模板