adenvt

Untitled

Apr 4th, 2019
122
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.47 KB | None | 0 0
  1. // In Vuex
  2. import _ from 'lodash'
  3.  
  4. const state = {
  5. users: []
  6. }
  7.  
  8. const getters = {
  9. userGroup (state) {
  10. return _.groupBy(state.users, 'title') // using lodash groupBy, https://lodash.com/docs/4.17.11#groupBy
  11. }
  12. }
  13.  
  14. const actions = {
  15. getUser () {
  16. axios.get('/')
  17. }
  18. }
  19.  
  20. export default {
  21. state, getters, actions
  22. }
  23.  
  24. // In Component
  25.  
  26. export default {
  27. data () => ({
  28. }),
  29. computed: {
  30. group () {
  31. return this.$store.getters.userGroup
  32. }
  33. }
  34. }
Advertisement
Add Comment
Please, Sign In to add comment