Skip to content

Instantly share code, notes, and snippets.

@SurbhiKatariya
Last active April 4, 2020 15:58
Show Gist options
  • Save SurbhiKatariya/6dad2de94bbf85f38994fb6d2034882b to your computer and use it in GitHub Desktop.
Save SurbhiKatariya/6dad2de94bbf85f38994fb6d2034882b to your computer and use it in GitHub Desktop.
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