javascript - 使 v-menu 标题保持固定在顶部
问题描述
所以我试图在我的 VueJS 应用程序中做一个通知组件,但我正在努力获得一个在单击固定时打开的菜单的标题。
这是组件的代码:
<template>
<v-menu
max-width="400px"
max-height="300px"
allow-overflow
v-model="menu"
:close-on-content-click="false"
:nudge-width="200"
offset-x
>
<template v-slot:activator="{ on }">
<v-icon v-on="on" @click="menu = true">mdi-bell</v-icon>
</template>
<v-card>
<v-list>
<v-list-item>
<v-list-item-content>
<v-list-item-title style="position:fixed;" class="text-center"
>This Should Be Fixed</v-list-item-title
>
</v-list-item-content>
</v-list-item>
</v-list>
<v-divider></v-divider>
<v-list>
<v-list-item>Message</v-list-item>
<v-list-item>Message</v-list-item>
<v-list-item>Message</v-list-item>
<v-list-item>Message</v-list-item>
<v-list-item>Message</v-list-item>
<v-list-item>Message</v-list-item>
<v-list-item>Message</v-list-item>
<v-list-item>Message</v-list-item>
<v-list-item>Message</v-list-item>
</v-list>
<v-btn text @click="menu = false">Cancel</v-btn>
<v-btn color="primary" text @click="menu = false">Save</v-btn>
</v-card>
</v-menu>
我试过了<v-app-bar fixed>Title</v-app-bar>
,也不管用。有谁知道是什么原因造成的?
解决方案
诀窍是使用 av-card
作为菜单内容,并overflow-y: scroll
在内容上设置固定高度:
<v-menu
max-width="400px"
v-model="menu"
:close-on-content-click="false"
:nudge-width="200"
offset-x
>
<template v-slot:activator="{ on }">
<v-icon v-on="on" @click="menu = true">mdi-bell</v-icon>
</template>
<v-card scrollable>
<v-card-title>
This Should Be Fixed
</v-card-title>
<v-card-text style="height: 280px; overflow-y: scroll"> <!--THIS IS IMPORTANT!-->
<v-list>
<v-list-item>Message</v-list-item>
<v-list-item>Message</v-list-item>
<v-list-item>Message</v-list-item>
<v-list-item>Message</v-list-item>
<v-list-item>Message</v-list-item>
<v-list-item>Message</v-list-item>
<v-list-item>Message</v-list-item>
<v-list-item>Message</v-list-item>
<v-list-item>Message</v-list-item>
</v-list>
</v-card-text>
<v-card-actions>
<v-btn text @click="menu = false">Cancel</v-btn>
<v-btn color="primary" text @click="menu = false">Save</v-btn>
</v-card-actions>
</v-card>
</v-menu>
推荐阅读
- java - 有人可以澄清为什么在下面的代码中名字被打印为 null 吗?
- c# - C# 中的“温度”属性
- fish - Fish 在 config.fish 中运行缩写
- node.js - 连接到数据库时出现 DotEnv 错误
- json - 我每次都必须使用 ctrl+s 来更新 UI 。Setstate() 不工作。在哪里正确使用 setstate()?
- qt - 什么时候使用 layer.enabled 是个好主意?
- opencv - 每当我构建 opencv-python 时,opencv_python.libs 文件夹都会丢失
- xml - 如何在odoo的标题中移动字段状态'
- python - Python,Pandas:将特定值插入空单元格(按列)
- python-3.x - cx_Oracle ORA-00933 SQL 命令未正确结束