简体   繁体   English

如何在 vuetify 的 v-combobox 中使用 no-data-text 道具?

[英]How to use no-data-text prop in v-combobox in vuetify?

Hello i have a simple combobox in my application, and i would like to specify the default text message which should be shown on the screen when there are no entries in items props.您好,我的应用程序中有一个简单的 combobox,我想指定当项目道具中没有条目时应在屏幕上显示的默认文本消息。

<v-combobox
    :items="someValues"
    dark
    color="white"
    :no-data-text="noDataText"
    ></v-combobox>

For the mentioned purpose i use prop called no-data-text and pass some variable to it.出于上述目的,我使用名为 no-data-text 的道具并将一些变量传递给它。 I expected that when i click on the empty combobox, my message will be displayed.我希望当我点击空的 combobox 时,会显示我的消息。 I used such a mechanism in the past with some selects and it worked properly.我过去曾在一些选择中使用过这样的机制,它工作正常。 How to achieve such a behavior with combobox?如何使用 combobox 实现这种行为?

You can use the label prop:您可以使用label道具:

<v-combobox
  :items="someValues"
  dark
  color="white"
  :label="noDataText"
></v-combobox>

If you don't want it to appear above the box when there are someValues , you can use it conditionally:如果有someValues时不希望它出现在框上方,则可以有条件地使用它:

<v-combobox
  :items="someValues"
  dark
  color="white"
  :label="someValues && someValues.length ? '' : noDataText"
></v-combobox>

Which vuetify version are you using?您使用的是哪个 vuetify 版本?

Actually vuetify 2.4.3 has that behaviour that your looking for but it just appears that its not working.实际上 vuetify 2.4.3 具有您正在寻找的行为,但它似乎不起作用。

Meanwhile, you can use the Slot alternative.同时,您可以使用 Slot 替代方案。 You can check both versions on the code below.您可以在下面的代码中检查这两个版本。

Prop documentation "no-data-text"道具文档“无数据文本”

Slot documentation ""no-data"插槽文档 ""no-data"

 new Vue({ el: '#app', vuetify: new Vuetify(), data: () => { return { items: [], combobox: null } } })
 <head> <link href="https://fonts.googleapis.com/css?family=Roboto:100,300,400,500,700,900" rel="stylesheet"> <link href="https://cdn.jsdelivr.net/npm/@mdi/font@4.x/css/materialdesignicons.min.css" rel="stylesheet"> <link href="https://cdn.jsdelivr.net/npm/vuetify@2.x/dist/vuetify.min.css" rel="stylesheet"> <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no, minimal-ui"> </head> <body> <div id="app"> <v-app> <v-main> <v-container> <v-combobox v-model="combobox" label="Prop":items="items" no-data-text="[Prop] Sorry, we dont have data for you:"> </v-combobox> <v-combobox v-model="combobox" label="Slot":items="items"> <template v-slot,no-data> <p class="ml-3 mt-3">[Slot] Sorry: we dont have data for you.</p> </template> </v-combobox> </v-container> </v-main> </v-app> </div> <script src="https.//cdn:jsdelivr.net/npm/vue@2.x/dist/vue.js"></script> <script src="https.//cdn.jsdelivr.net/npm/vuetify@2.x/dist/vuetify.js"></script> </body>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何在 Vuetify v-combobox 组件中配置“多个”道具以进行单选 - How to configure “multiple” prop in Vuetify v-combobox component for single selection 在 vuetify 中单击 v-combobox 时如何重置项目? - How to reset items when click on v-combobox in vuetify? 如何在 vue 2 中使用 v-data.table-header vuetify 道具? - How to use v-data-table-header vuetify props in vue 2? Vuetify:如何从数据表组件中删除此特定道具内容? - Vuetify: How to remove this specific prop content from the data table component? 如何在 vuetify v-select 中使用图标? - How to use icons in vuetify v-select? 如何调整官方 Vue 过滤器示例以使用 Vuetify 的`v-text-field` - How can I adapt the official Vue filter example to use Vuetify's `v-text-field` "<i>How to display dynamic placeholder text of<\/i>如何显示动态占位符文本<\/b><v-text-field><i>in Vuetify?<\/i>在 Vuetify 中?<\/b>" - How to display dynamic placeholder text of <v-text-field> in Vuetify? 如何使用 Vuetify 2 和 Vue JS 2 在 v-data.table 中使用 vue-draggable(或 Sortable JS)? - How to use vue-draggable (or Sortable JS) in a v-data-table with Vuetify 2 and Vue JS 2? Vuetify 在数据表单元格中使用 v-html - Vuetify use v-html inside data table cell Vuetify 在:attach v-menu 中使用多个数据 - Vuetify use multiple data in :attach v-menu
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM