E
E
edleman2019-11-21 09:37:35
Vue.js
edleman, 2019-11-21 09:37:35

Re-selecting value in vue-select package?

In Laravel, I get data using a model.

public function onSearch(Request $request){
    $search = Model::where('text', 'LIKE', '%'.$request->search.'%')->get();

    return response()->json(['search' => $search]);
}

In the VUE component I do the following:
<template>
                <v-select
                          :v-model="option"
                          :filterable="false"
                          :options="options"
                          @search="onSearch">
                    <template slot="no-options">
                        search
                    </template>
                    <template slot="option" slot-scope="option">
                        <div class="d-center">
                            {{ option.short_name }}
                        </div>
                    </template>
                    <template slot="selected-option" slot-scope="option">
                        <div class="selected d-center">
                            {{ option.short_name }}
                        </div>
                    </template>
                </v-select>
 </template>

<script>
    import axios from 'axios'
    import _ from 'lodash'
    export default {
        data() {
            return {
               option: null,
               options: [],
           }
         },
       methods: {
            onSearch(search, loading) {
                loading(true);
                this.search(loading, search, this);
            },
            search: _.debounce((loading, search, vm) => {
                let formData = new FormData();
                formData.append('search', search);
                axios.post('/search', formData).then(response => {
                   vm.options = response.data.search;
                    loading(false);
                });
            }, 350)
        }
    }
</script>

When you run the code in the select, the data is found and displayed in the select, but if, for example, you decide to change the selected select, then the search for new data works, but when you select, they are not re-selected. If you click the cross on the right and make a new selection, then it works.
Documentation itself: https://vue-select.org/guide/ajax.html#loading-opt...
There is also an example on the documentation site: https://codepen.io/sagalbot/pen/POMeOX
Tried to do this example works fine, no complaints.
Actually, the value is not re-selected, what did you do wrong? Tell me please. Thank you.

Answer the question

In order to leave comments, you need to log in

2 answer(s)
O
Oleg Koltunov, 2019-11-21
@edleman

Remove :v-model from v-select.

G
genius_spirit, 2019-11-21
@genius_spirit

v-model cannot bind like you have (:v-model="option") it's always v-model="option"

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question