vue.js - 带 Bootstrap 的 Vue js,导航栏菜单不起作用

标签 vue.js navbar boot

我在 Vue js 上实现了一个导航栏菜单,它是响应式的,它非常适合桌面,但是当我测试响应式模式时,菜单不起作用,这是按钮切换:

        <button
          class="navbar-toggler"
          type="button"
          data-toggle="collapse"
          data-target="#sidebarMenu"
          aria-controls="sidebarMenu"
          aria-expanded="false"
          aria-label="Toggle navigation"
        >
          <i class="fas fa-bars"></i>
        </button>

在我的侧边栏上有:

<nav id="sidebarMenu" class="collapse d-lg-block sidebar collapse bg-white">

你可以看到引用sidebarMenu所以,我不知道出了什么问题?我将我的代码加载到 CodesandBox.io

你可以检查一下并告诉我出了什么问题吗?请

最佳答案

你需要使用 vue 指令而不是 data-toggle 和 data-target ...这是在 vue 中应该如何完成的:

<template>
<div>
    <!-- Button to toggle the sidebar -->
    <button
    class="navbar-toggler"
    type="button"
    @click="toggleSidebar"
    >
    <i class="fas fa-bars"></i>
    </button>

    <!-- Sidebar -->
    <nav
    id="sidebarMenu"
    :class="{ 'collapse': !sidebarOpen, 'd-lg-block': sidebarOpen, 'bg-white': sidebarOpen }"
    >
    <!-- Sidebar content -->
    </nav>
</div>
</template>

<script>
export default {
data() {
    return {
    sidebarOpen: true, // Initial state, you can set it to false if you want it closed by default
    };
},
methods: {
    toggleSidebar() {
    // Toggle the sidebarOpen state
    this.sidebarOpen = !this.sidebarOpen;
    },
},
};
</script>

关于vue.js - 带 Bootstrap 的 Vue js,导航栏菜单不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/77134376/

相关文章:

vue.js - 如何修复警告 : `getFieldDecorator` will override `value` , 所以请不要直接设置 `value and v-model` 并使用 `setFieldsValue` 设置它。?

javascript - 路由器不显示 vue 组件

css - Bootstrap 4 导航栏不会在 Angular4 中崩溃

android - 如何添加脚本以在 Android 上启动/启动?

linux - 在启动时从 USB 挂载 ISO 镜像

jquery - 集成同位素和 Vue

javascript - 如何使用 Vue.js 预加载图像?

html - 带有透明三 Angular 形的导航栏事件链接

css - 滚动页面时导航栏不粘在顶部

ruby-on-rails - 在初始化时设置 default_url_options