I'm using a Vue Resource to send HTTP requests to my Sails.JS backend.
Everything is working fine, except the only problem is the where
clause in Sails isn't implementing the way it should.
Here's my code:
My Template:
<div class="content">
<input type="text" class="search" placeholder="Search Users" v-model="search">
<button v-on:click="searchUsers" class="add-btn search-btn"> <i class="fas fa-search"></i> </button>
<div class="list">
<ul class="lists-group">
<template v-for="(user, index) in users">
<router-link v-bind:to="'users/user/' + user.id" class="lists-item">{{ user.firstName }} {{ user.lastName }}</router-link>
</template>
</ul>
</div>
</div>
My Script
export default {
data: function() {
return {
search : '',
users: [],
}
},
methods: {
searchUsers: function() {
this.$http.get('http://localhost:1337/users?firstName=' + this.search).then(result => {
this.users = result.body;
})
if (!this.search) this.getAllUsers();
},
getAllUsers: function() {
this.$http.get('http://localhost:1337/api/v1/users').then(users => {
this.users = users.body.users;
})
}
},
created: function() {
this.$http.get('http://localhost:1337/api/v1/users').then(users => {
this.users = users.body.users;
})
}
}
I tried to use a get request with { params : { where : { firstName : contains : this.search } } }
but it's still not working.
What's the best approach to send a query like this?
'http://localhost:1337/users?where={"firstName":{"contains":"UserName"}, "occupation": "doctor"}'