0

I am trying to build a vue3 app with bootstrap 5. I am adding tabs. I am able to click on the tabs, but the tab-content is stuck on the initial tab. How do I fix that?

package.json:

{
  "name": "my-dashboard",
  "version": "0.1.0",
  "private": true,
  "scripts": {
    "serve": "vue-cli-service serve",
    "build": "vue-cli-service build",
    "lint": "vue-cli-service lint"
  },
  "dependencies": {
    "@fortawesome/fontawesome-svg-core": "^6.5.2",
    "@fortawesome/free-brands-svg-icons": "^6.5.2",
    "@fortawesome/free-solid-svg-icons": "^6.5.2",
    "@fortawesome/vue-fontawesome": "^3.0.6",
    "@popperjs/core": "^2.11.8",
    "axios": "^1.6.8",
    "bootstrap": "^5.3.3",
    "core-js": "^3.8.3",
    "crypto-browserify": "^3.12.0",
    "datatables.net-vue3": "^3.0.1",
    "dotenv": "^16.4.5",
    "highcharts": "^11.4.1",
    "highcharts-vue": "^2.0.1",
    "os-browserify": "^0.3.0",
    "path": "^0.12.7",
    "path-browserify": "^1.0.1",
    "stream-browserify": "^3.0.0",
    "vm-browserify": "^1.1.2",
    "vue": "^3.4.21",
    "vue-axios": "^3.5.2",
    "vue-jalali-moment": "^1.0.0",
    "vue3-daterange-picker": "^1.0.1"
  },
  "devDependencies": {
    "@babel/core": "^7.12.16",
    "@babel/eslint-parser": "^7.12.16",
    "@types/bootstrap": "^5.2.10",
    "@vue/cli-plugin-babel": "~5.0.0",
    "@vue/cli-plugin-eslint": "~5.0.0",
    "@vue/cli-service": "~5.0.0",
    "eslint": "^7.32.0",
    "eslint-plugin-vue": "^8.0.3",
    "sass": "^1.75.0",
    "sass-loader": "^14.2.1",
    "style-loader": "^4.0.0"
  },
  "eslintConfig": {
    "root": true,
    "env": {
      "browser": true,
      "es2021": true
    },
    "extends": [
      "plugin:vue/vue3-essential",
      "eslint:recommended"
    ],
    "parserOptions": {
      "parser": "@babel/eslint-parser",
      "ecmaVersion": 2021,
      "requireConfigFile": false
    },
    "rules": {}
  },
  "browserslist": [
    "> 1%",
    "last 2 versions",
    "not dead",
    "not ie 11"
  ]
}

navBar.vue:

<template>
  <div id="navs" class="m-2">
    <ul class="nav nav-tabs" role="tablist">
      <li class="nav-item">
        <a
          class="nav-link"
          :class="{ active: activeTab === 'web' }"
          @click="activeTab = 'web'"
          href="#web"
          ><font-awesome-icon icon="globe"
        /></a>
      </li>
      <li class="nav-item">
        <a
          class="nav-link"
          :class="{ active: activeTab === 'flag' }"
          @click="activeTab = 'flag'"
          href="#flag"
          ><font-awesome-icon icon="flag"
        /></a>
      </li>
      <li class="nav-item">
        <a
          class="nav-link"
          :class="{ active: activeTab === 'fb' }"
          @click="activeTab = 'fb'"
          href="#fb"
          ><font-awesome-icon :icon="{ prefix: 'fab', iconName: 'facebook' }"
        /></a>
      </li>
      <li class="nav-item">
        <a
          class="nav-link"
          :class="{ active: activeTab === 'twitter' }"
          @click="activeTab = 'twitter'"
          href="#twitter"
          ><font-awesome-icon
            :icon="{ prefix: 'fab', iconName: 'square-x-twitter' }"
        /></a>
      </li>
      <li class="nav-item">
        <a
          class="nav-link"
          :class="{ active: activeTab === 'yt' }"
          @click="activeTab = 'yt'"
          href="#yt"
          ><font-awesome-icon :icon="{ prefix: 'fab', iconName: 'youtube' }"
        /></a>
      </li>
      
    </ul>
  </div>
</template>

<script>
export default {
  name: "NavBar",
  data() {
    return {
      activeTab: "web",
    };
  },
};
</script>

<style scoped>
/* Add your component-specific styles here */
</style>

App.vue:

<template>
  <div id="container">
    <NavBar />
    <div class="tab-content">
      <div
        id="web"
        class="container tab-pane"
        :class="{ active: activeTab === 'web' }"
      >
        <h3 class="text-danger">Web</h3>
        <BaseElements />
        <chart></chart>
      </div>
      <div
        id="flag"
        class="container tab-pane"
        :class="{ active: activeTab === 'flag' }"
      >
        <h3 class="text-light">Country</h3>
      </div>
    </div>
  </div>
</template>

<script>
import "bootstrap/dist/css/bootstrap.min.css";
import NavBar from "./components/navBar.vue";
import BaseElements from "./components/BaseElements.vue";
import BarChart from "./components/BarChart";

export default {
  name: "App",
  components: {
    NavBar,
    BaseElements,
    chart: BarChart,
  },
  data() {
    return {
      activeTab: "web",
    };
  },
  methods: {
    handler() {
      var args = arguments;
      for (var arg of args) {
        if (arg instanceof Function) {
          arg();
        }
      }
    },
  },
};
</script>

<style>
body {
  margin: 0;
  background-color: #002a53 !important;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "Roboto", "Oxygen",
    "Ubuntu", "Cantarell", "Fira Sans", "Droid Sans", "Helvetica Neue",
    sans-serif;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

code {
  font-family: source-code-pro, Menlo, Monaco, Consolas, "Courier New",
    monospace;
}
</style>

Not sure why the tab content is not being changed.

1 Answer 1

0

I gave a very similar answer yesterday.

Mostly, Bootstrap here is only a CSS framework. It does not have any relation to VueJS' reactivity system. You have mostly a visual framework, not one that you could interact with. For that you should use bootstrap-vue but the project is dead.

Overall, as stated in my other answer: use any other UI library that has an active community behind it and works well with Vue3, there are plenty!

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.