Boostrap-vue toggle not dropping down

please can someone explain why toggle drop down isn’t functioning, when i click the toggle there isn’t an event on the key . and also I’m using vue and bootstrap for this my project

<!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">
    <title>my portfolio</title>
    <link href="https://cdn.jsdelivr.net/npm/bootstrap@5.0.2/dist/css/bootstrap.min.css" rel="stylesheet" />
    <script src="https://unpkg.com/vue@3/dist/vue.global.js"></script>
  </head>
<body> 
  <nav class="navbar navbar-expand-lg navbar-light bg-light">
    <a class="navbar-brand" href="#">EMMYTECH</a>
    <button class="navbar-toggler" type="button" data-toggle="collapse" data-target="#nav-collapse" aria-controls="nav-collapse" aria-expanded="false" aria-label="Toggle navigation">
      <span class="navbar-toggler-icon"></span>
    </button>
    <div class="collapse navbar-collapse" id="nav-collapse">
      <ul class="navbar-nav ml-auto">
        <li v-for="(page, index) in pages" class="nav-item" :key="index">
          <a class="nav-link"
             :class="{ active: activePage == index }"
             href="#"
             :title="`this page goes to the ${page.link.text} page`"
             @click.prevent="activePage = index">
            {{ page.link.text }}
          </a>
        </li>
      </ul>
    </div>
  </nav>  
     <div id='Content' class='container'>
        <h1>
            {{ pages[activePage].pageTitle }}
        </h1>
       <p>
        {{ pages[activePage].Content }}
       </p>
     </div>     
    <script>
       const { createApp } = Vue
       createApp({
          data() {
            return {
                activePage: 0,
                pages: [ 
                    {
                link: {text: 'Home', url: 'index.Home'},
                pageTitle: 'home page',
                Content: 'this is a home page',
                    },
                    {
                link: {text: 'About', url: 'index.About'},
                pageTitle: 'About page',
                Content: 'this is a About page',
                    },
                    {
                link: {text: 'Services', url: 'index.services'},
                pageTitle: 'services page',
                Content : 'this is  services page',
                    },   
                    {
                link: {text: 'contact', url: 'index.contact'},
                pageTitle: 'contact page',
                Content: 'this is a contact page',
                    },
                    {
                link: {text: 'Projects', url: 'index.projects'},
                pageTitle: 'Home page',
                Content: 'This is a home page',
                    }
              ],
              message: 'Hello Vue!',
              grettings: 'baba weyre'
            }
          } 
        }).mount('body');
      </script>
</body>
</html>
  1. You are not using the correct attributes, it is data-bs-toggle and data-bs-target in Bootstrap 5.
  1. You are missing the Bootstrap JS
<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.2.3/dist/js/bootstrap.bundle.min.js" integrity="sha384-kenU1KFdBIe4zVF0s0G1M5b4hcpxyD9F7jL+jjXkk+Q2h455rYXK/7HAuoJl+0I4" crossorigin="anonymous"></script>

There is also a warning in the console, which I believe you get rid of by putting the template code inside its own container and moving the Vue code script tag out of that container.

Code
<!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">
  <title>my portfolio</title>
  <link href="https://cdn.jsdelivr.net/npm/bootstrap@5.0.2/dist/css/bootstrap.min.css" rel="stylesheet" />
  <script src="https://unpkg.com/vue@3/dist/vue.global.js"></script>
</head>

<body>
  <div id="app">
    <nav class="navbar navbar-expand-lg navbar-light bg-light">
      <a class="navbar-brand" href="#">EMMYTECH</a>
      <button class="navbar-toggler" type="button" data-bs-toggle="collapse" data-bs-target="#nav-collapse" aria-controls="nav-collapse" aria-expanded="false" aria-label="Toggle navigation">
        <span class="navbar-toggler-icon"></span>
      </button>
      <div class="collapse navbar-collapse" id="nav-collapse">
        <ul class="navbar-nav ml-auto">
          <li v-for="(page, index) in pages" class="nav-item" :key="index">
            <a class="nav-link" :class="{ active: activePage == index }" href="#" :title="`this page goes to the ${page.link.text} page`" @click.prevent="activePage = index">
              {{ page.link.text }}
            </a>
          </li>
        </ul>
      </div>
    </nav>
    <div id='Content' class='container'>
      <h1>
        {{ pages[activePage].pageTitle }}
      </h1>
      <p>
        {{ pages[activePage].Content }}
      </p>
    </div>
  </div>
  <script>
    const {
      createApp
    } = Vue
    createApp({
      data() {
        return {
          activePage: 0,
          pages: [{
              link: {
                text: 'Home',
                url: 'index.Home'
              },
              pageTitle: 'home page',
              Content: 'this is a home page',
            },
            {
              link: {
                text: 'About',
                url: 'index.About'
              },
              pageTitle: 'About page',
              Content: 'this is a About page',
            },
            {
              link: {
                text: 'Services',
                url: 'index.services'
              },
              pageTitle: 'services page',
              Content: 'this is  services page',
            },
            {
              link: {
                text: 'contact',
                url: 'index.contact'
              },
              pageTitle: 'contact page',
              Content: 'this is a contact page',
            },
            {
              link: {
                text: 'Projects',
                url: 'index.projects'
              },
              pageTitle: 'Home page',
              Content: 'This is a home page',
            }
          ],
          message: 'Hello Vue!',
          grettings: 'baba weyre'
        }
      }
    }).mount('#app');
  </script>
  <script src="https://cdn.jsdelivr.net/npm/bootstrap@5.2.3/dist/js/bootstrap.bundle.min.js" integrity="sha384-kenU1KFdBIe4zVF0s0G1M5b4hcpxyD9F7jL+jjXkk+Q2h455rYXK/7HAuoJl+0I4" crossorigin="anonymous"></script>
</body>
</html>

thank you very much for this wonderful answer to my problem . :heart_eyes:

This topic was automatically closed 182 days after the last reply. New replies are no longer allowed.