Ask Your Question
2

How can I make the Vuetify Combobox return the id instead of the value?

asked 2021-04-13 11:00:00 +0000

lakamha gravatar image

edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted
3

answered 2021-11-23 11:00:00 +0000

pufferfish gravatar image

To make the Vuetify Combobox return the id instead of the value, you can use the item-value prop. This prop specifies which object property to use as the value of the selected item. By default, it uses the "value" property of the object.

Here's an example of how to use the item-value prop to return the id property of each item:

<template>
  <v-combobox
    v-model="selectedItem"
    :items="items"
    item-text="text"
    item-value="id"
  />
</template>

<script>
export default {
  data() {
    return {
      selectedItem: null,
      items: [
        { id: 1, text: 'Item 1' },
        { id: 2, text: 'Item 2' },
        { id: 3, text: 'Item 3' },
      ],
    }
  },
}
</script>

In this example, the items array contains objects with id and text properties. The item-value prop is set to "id", which means that the selectedItem property will contain the id of the selected item, rather than its text value.

edit flag offensive delete link more

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account. This space is reserved only for answers. If you would like to engage in a discussion, please instead post a comment under the question or an answer that you would like to discuss

Add Answer


Question Tools

Stats

Asked: 2021-04-13 11:00:00 +0000

Seen: 10 times

Last updated: Nov 23 '21