设置下拉菜单中显示的项目数 Vuetify

huangapple go评论71阅读模式
英文:

v-select set number of items shown in dropdown Vuetify

问题

我有以下的 v-select:

设置下拉菜单中显示的项目数 Vuetify

它有 7 个选项(每个工作日一个),但我希望在打开时显示所有 7 个,而不仅仅是前 6 个带有滚动条。我似乎找不到 v-select 的 API 选项来实现这个。

我在 Vuetify 页面和一些 StackOverflow 问题上进行了搜索。

我该如何做,如果我漏掉了什么:我应该搜索什么?

谢谢!

英文:

I have the following v-select:

设置下拉菜单中显示的项目数 Vuetify

It has 7 items (for each weekday) but I want it to show all 7 when it's opened, not only the first 6 with a scrollbar. I can't seem to find an v-select API option for that.
I searched on the Vuetify page and on several StackOverflow questions.

How can I do that and if I missed something: What should I have been searching for?

Thanks!

答案1

得分: 1

你可以取消设置max-height,这样对话框就不会受到限制。

这是v-menu的底层属性,你可以使用:menu-props来传递它:

<v-select
  :menu-props="{maxHeight: 'unset'}"
  ...

这里有一个片段(你需要展开它以查看完整的高度):

<!-- begin snippet: js hide: false console: false babel: false -->

<!-- language: lang-js -->
const {
  createApp,
  ref
} = Vue;
const {
  createVuetify
} = Vuetify
createApp({}).use(createVuetify()).mount('#app')

<!-- language: lang-html -->
<link rel="stylesheet" type="text/css" href="https://cdn.jsdelivr.net/npm/vuetify@3.1.6/dist/vuetify.min.css" />
<div id="app">
  <v-app>
    <div>
      <v-select
        label="Weekday" 
        :items="['Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat', 'Sun']"
        :menu-props="{maxHeight: 'unset'}"
      ></v-select>
    </div>
  </v-app>
</div>
<script src="https://unpkg.com/vue@3/dist/vue.global.prod.js"></script>
<script src="https://cdn.jsdelivr.net/npm/vuetify@3.1.6/dist/vuetify.min.js"></script>

<!-- end snippet -->

它应该在使用Vuetify的Vue 2版本上起作用,它的:menu-props文档记录得更详细。

这对你有用吗?

英文:

You can unset max-height, so that the dialog is not limited.

It's a property on the underlying v-menu, you pass it using :menu-props:

&lt;v-select
  :menu-props=&quot;{maxHeight: &#39;unset&#39;}&quot;
  ...

Here is a snippet (you need to expand it to see it in full height though):

<!-- begin snippet: js hide: false console: false babel: false -->

<!-- language: lang-js -->

const {
  createApp,
  ref
} = Vue;
const {
  createVuetify
} = Vuetify
createApp({}).use(createVuetify()).mount(&#39;#app&#39;)

<!-- language: lang-html -->

&lt;link rel=&quot;stylesheet&quot; type=&quot;text/css&quot; href=&quot;https://cdn.jsdelivr.net/npm/vuetify@3.1.6/dist/vuetify.min.css&quot; /&gt;
&lt;div id=&quot;app&quot;&gt;
  &lt;v-app&gt;
    &lt;div&gt;
      &lt;v-select
        label=&quot;Weekday&quot; 
        :items=&quot;[&#39;Mon&#39;, &#39;Tue&#39;, &#39;Wed&#39;, &#39;Thu&#39;, &#39;Fri&#39;, &#39;Sat&#39;, &#39;Sun&#39;]&quot;
        :menu-props=&quot;{maxHeight: &#39;unset&#39;}&quot;
      &gt;&lt;/v-select&gt;
    &lt;/div&gt;
  &lt;/v-app&gt;
&lt;/div&gt;
&lt;script src=&quot;https://unpkg.com/vue@3/dist/vue.global.prod.js&quot;&gt;&lt;/script&gt;
&lt;script src=&quot;https://cdn.jsdelivr.net/npm/vuetify@3.1.6/dist/vuetify.min.js&quot;&gt;&lt;/script&gt;

<!-- end snippet -->

It should work the same using Vuetify for Vue 2, its :menu-props is actually documented a bit better.

Does that work for you?

huangapple
  • 本文由 发表于 2023年3月7日 08:50:17
  • 转载请务必保留本文链接:https://go.coder-hub.com/75657128.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定