Skip to content

Instantly share code, notes, and snippets.

@SurbhiKatariya SurbhiKatariya/Users.vue
Last active Apr 4, 2020

Embed
What would you like to do?
Fetch data with query
<script>
export default {
data () {
return {
userList: [],
isLoading: false
}
},
created () {
const vm = this
vm.getUserList({ character: '@' })
},
methods: {
/**
* fetch users records using apollo client
*/
getUserList (variables = {}) {
const vm = this
vm.isLoading = true
vm.$apolloProvider.defaultClient
// it will fire queries here
.query({
query: GET_USER_DETAILS,
variables: {
...variables
}
// fetchPolicy: 'cache-and-network'
})
.then(result => {
vm.userList = result.data.allUsers
vm.isLoading = result.data.loading
})
.catch(error => {
// write your error message here
console.log(error)
})
}
}
}
</script>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.