I'm working on a VueJS web app, in which I need to query a db of peoples names based off user input.
In my server.js file I have my API endpoint which I want to query and have it hosted on localhost:4000
//Staff
app.get('/staff', (req,res) => {
connection.query(SELECT_CERTAIN_STAFF, (error,results) => {
if(error){
return res.send(error)
}
else {
console.log('Selected STAFF from People')
return res.json({
data: results
})
}
})
})
In my Search.vue this is my search method
//Data
data(){
return {
input: '',
errors: ''
}
},
//Methods
methods:{
search(keyboard){
console.log(this.input)
axios.get('http://localhost:4000/staff?username='+this.input)
.then(response => {
console.log(JSON.stringify(response.data.data))
})
.catch(error => {
console.log(error)
this.errors = error
})
console.log(keyboard.value)
}
},
I added console.log(this.input) + console.log(keyboard.value) to test the correct input is being taken from the user, which it is
In my response, the console.log(JSON.stringify(response.data.data)) is just returning the data in the endpoint /staff, and is not filtering any of the data based on user input.
Anyone have any idea why it's doing this/ different approach? Have I set up the API endpoints correctly?
Thanks