Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

UsmanBasharmal's avatar

vue-search-select in laravel and vuejs could not load data

I am use vue-search-select in laravel vuejs the problem is that it dose not load data from api it shows the dropdown list empty but when I check Booksarray there are data I mean array is loaded with data .

code in vue is like below

 <div class="form-group">
              <model-select :options="Booksarray" v-model="item2" placeholder="انتخاب کتاب"></model-select>
            </div>

data() {
         return {
        Booksarray:[],
        item2: "",
       }

 axios.get("api/getAllBook").then(({ data }) => (this.Booksarray = data));
0 likes
13 replies
UsmanBasharmal's avatar

it gives me this error <model-list-select> - did you register the component correctly

Sti3bas's avatar

@usmanbasharal because you have to import it:

import { ModelListSelect } from 'vue-search-select';

export default {
   components: {
      ModelListSelect
   },
   //...
}

UsmanBasharmal's avatar

I did this but the dropdown is still empty

<model-list-select :list="Booksarrays" option-value="Booksarrays.id" option-text="Booksarrays.name" v-model="form.book_id" placeholder="select item" @change="getBook_id()" ></model-list-select>

Sti3bas's avatar

@usmanbasharal try:

<model-list-select
   :list="Booksarray"
   option-value="id"
   option-text="name"
   v-model="form.book_id"
   placeholder="select item"
></model-list-select>

and make sure you're getting the right response from your API. Also check the console if you get any errors.

UsmanBasharmal's avatar

thanks it worked but when I am typing something in dropdown search box it dose not show me what I typed

UsmanBasharmal's avatar

import { ModelListSelect } from "vue-search-select";

export default {  components: {    ModelListSelect,},
data() {    return {  Booksarray: [],
    form: new Form({
    id: "",
    book_id: "",
    shell_id: "",
    purchase_id: "",
    quantity: "",
    unitprice: "",
    supplydate: ""
  }),

   }
    ,methods: { loadStocks() {
  // $(".hideme").hide();

  // if (this.$gate.isAdmin() || this.$gate.isUser()) {
  this.$Progress.start(); // NProgress.start();
  axios.get("api/Stock").then(({ data }) => (this.Stocks = data));

  axios.get("api/getAllStock").then(({ data }) => (this.data = data));
  axios.get("api/getAllBook").then(({ data }) => (this.Books = data));
  axios.get("api/getAllShell").then(({ data }) => (this.Shells = data));

  axios.get("api/getAllBook").then(({ data }) => (this.Booksarray = data));
  axios
    .get("api/getAllPurchase")
    .then(({ data }) => (this.Purchases = data));
  this.alert();
  this.$Progress.finish();

  // }
  // NProgress.done();
},},
  created() {
Fire.$on("searching", () => {
  let query = this.search;
  axios
    .get("api/searchStock?q=" + query)
    .then(data => {
      this.Stocks = data.data;
    })

    .catch(() => {});
});
this.loadStocks();
// load the page after 3 secound
Fire.$on("refreshPage", () => {
  this.loadStocks();
});
 }
UsmanBasharmal's avatar

I want to get the books by calling the below function while I select id from drop down list how to do it in normal dropdown box in the select section @change we call the function but I do not know how to do it in model-list-select is there any option for this?

         getBook_id: function() {
  
         axios
      .get("api/getBybook_ids", {
        params: { book_id: this.form.book_id }
      })
      .then(
        function(response) {
          this.Stocks = response.data.data;
        }.bind(this)
      );
    // this.$Progress.finish();
    // this.GridLoader.finish();
    this.seen = false;
  }
},

Please or to participate in this conversation.