I am currently diving into the world of laravel combined with Vue js. I am working on integrating a search engine using vue js components, and I would greatly appreciate any help you can provide. Thank you in advance.
Below is the Vue js component where the search input is located:
<template>
<div class="container">
<form>
<input
class="form-control"
placeholder="Search"
type="search"
v-model="searchTerm"
@keyup="searchProducts"
>
</form>
</div>
</template>
This snippet shows my app.js file configuration:
const { default: Axios } = require('axios');
require('./bootstrap');
window.Vue = require('vue');
Vue.component('example-component', require('./components/ExampleComponent.vue').default);
const app = new Vue({
el: '#app',
created(){
this.fetchProducts();
},
data: {
products:[],
searchTerm: '',
searchTimeout:''
},
methods: {
fetchProducts(){
Axios.get('./products', {
params:{
filter: this.searchTerm
}
})
.then(res => {
this.products = res.data.data ;
})
.catch( error => {
console.log( error.response )
});
},
searchProducts(){
clearTimeout( this.searchTimeout = setTimeout(this.fetchProducts, 360) )
}
}
});
Finally, I embed my Vue js component within a blade view:
<div id="app">
<example-component></example-component>
</div>