Advertisement
Guest User

Untitled

a guest
Nov 21st, 2017
76
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.54 KB | None | 0 0
  1. <script>
  2. import axios from 'axios'
  3. export default {
  4. data () {
  5. return {
  6. search: '',
  7. totalItems: 0,
  8. items: [],
  9. loading: true,
  10. pagination: {},
  11. headers: [
  12. { text: 'Username', value: 'username' },
  13. { text: 'Email', value: 'email' }
  14. ]
  15. }
  16. },
  17. watch: {
  18. pagination: {
  19. handler () {
  20. this.getDataFromApi()
  21. },
  22. deep: true
  23. }
  24. },
  25. mounted () {
  26. this.getDataFromApi()
  27. },
  28. methods: {
  29. getDataFromApi () {
  30. this.loading = true
  31. const { sortBy, descending, page, rowsPerPage } = this.pagination
  32. const searchval = this.search
  33. let ordering = null
  34. let offset = null
  35. if (descending) {
  36. ordering = '-' + sortBy
  37. } else {
  38. ordering = sortBy
  39. }
  40. offset = (page - 1) * rowsPerPage
  41. axios({
  42. method: 'get',
  43. baseURL: '/api/users/?offset=' + offset + '&limit=' + rowsPerPage + '&ordering=' + ordering + '&search=' + searchval,
  44. headers: {
  45. Authorization: 'Token bc7ff5323264d2e80afb50a9ec2d93d15bb3c696'
  46. }
  47. })
  48. .then((response) => {
  49. console.log(response)
  50. this.items = response.data.results
  51. this.totalItems = response.data.count
  52. this.loading = false
  53. })
  54. .catch((error) => {
  55. console.log(error)
  56. this.loading = false
  57. })
  58. }
  59. }
  60. }
  61. </script>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement