Last active
April 4, 2020 15:58
-
-
Save SurbhiKatariya/6dad2de94bbf85f38994fb6d2034882b to your computer and use it in GitHub Desktop.
Fetch data with query
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<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