You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Vuelify新手求助:v-navigation-drawer无法在左侧显示

解决v-navigation-drawer不显示的问题

以下是几个常见的排查和解决方向:

  • 确认Vuetify组件已正确注册
    如果是Vue3项目,先检查main.js/ts里是否完整初始化了Vuetify,全局导入所有组件或按需导入。如果是按需导入单个组件,要在使用v-navigation-drawer的组件里明确导入:

    <script setup>
    import { VNavigationDrawer } from 'vuetify/components'
    </script>
    
  • 控制抽屉的显示状态
    v-navigation-drawer默认是隐藏状态,必须通过v-model绑定一个布尔值来控制它显示。比如设置默认打开:

    <template>
      <v-navigation-drawer v-model="drawerVisible">
        <!-- 必须添加抽屉内容,否则可能因高度为0看不见 -->
        <v-list>
          <v-list-item title="首页"></v-list-item>
          <v-list-item title="设置"></v-list-item>
        </v-list>
      </v-navigation-drawer>
    </template>
    
    <script setup>
    import { ref } from 'vue'
    import { VNavigationDrawer, VList, VListItem } from 'vuetify/components'
    
    const drawerVisible = ref(true)
    </script>
    
  • 给抽屉添加内容或设置最小高度
    空抽屉会因为高度为0而无法显示,要么添加实际内容(比如菜单列表),要么给抽屉设置最小高度样式:

    <v-navigation-drawer v-model="drawerVisible" style="min-height: 100vh;">
      <div>测试内容</div>
    </v-navigation-drawer>
    
  • 检查SideBar组件的内部配置
    你的主组件结构没问题(用VApp包裹侧边栏和主内容),但要确保SideBar.vue里的抽屉配置正确。比如给抽屉加上permanent属性强制显示,避免自动收起:

    <!-- SideBar.vue -->
    <template>
      <v-navigation-drawer permanent>
        <v-list>
          <v-list-item title="菜单项1"></v-list-item>
          <v-list-item title="菜单项2"></v-list-item>
        </v-list>
      </v-navigation-drawer>
    </template>
    
    <script setup>
    import { VNavigationDrawer, VList, VListItem } from 'vuetify/components'
    </script>
    

内容的提问来源于stack exchange,提问作者user51375

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.10 19:25:13