0

I don't know how to save the item-value in a variable in the component <v-autocomplete> of Vue.js. I want to save it in idLibro.

<template>
    <v-container grid-list-md>
      <v-layout row wrap>
        <v-autocomplete
        :disabled="!isEditing"
        :items="showTitleBooks"
        :filter="customFilter"
        color="white"
        item-text="name"
        item-value="id"
        label="Book"
        >
        </v-autocomplete>
    </v-layout>
  </v-container>
</template>

<script>
export default {
  data() {
    return {
      books: [],
      showTitleBooks: [],
      idLibro: "",
    };
  },
  methods: {
    getBooks() {
      this.$axios
        .get("http://localhost:8080/libros")
        .then(data => {
          this.books = data.data;
          for (const i of this.books) {
            this.showTitleBooks.push({ name: i.titulo, id: i.id_libro });
          }
          console.log(this.books);
        })
        .catch(() => {
          console.log("No hay libros");
        });
    },
};
</script>
calvin11
  • 187
  • 1
  • 17
  • See this example: https://github.com/vuetifyjs/vuetify/blob/master/packages/docs/src/examples/autocompletes/simple/api.vue – Sándor Bakos Feb 21 '20 at 21:43

1 Answers1

1
<v-autocomplete
  v-model="idLibro"
>
</v-autocomplete>
Lyde Su
  • 182
  • 1
  • 3
  • 1
    While this code may answer the question, providing additional context regarding how and/or why it solves the problem would improve the answer's long-term value. – Lex Webb Feb 27 '20 at 10:44
  • Roger that, I will come back after a while. – Lyde Su Feb 27 '20 at 11:49