Answer the question
In order to leave comments, you need to log in
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]);
}
<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>
Answer the question
In order to leave comments, you need to log in
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 questionAsk a Question
731 491 924 answers to any question