index.vue 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. <template>
  2. <div class="index">
  3. <div v-if="isMobile">
  4. <Home></Home>
  5. </div>
  6. <div v-if="!isMobile">
  7. <carousel>
  8. <kind-category @loadchild="loadProductKinds"></kind-category>
  9. </carousel>
  10. <advert></advert>
  11. <floor-list></floor-list>
  12. <news></news>
  13. <partner></partner>
  14. </div>
  15. </div>
  16. </template>
  17. <script>
  18. import { KindCategory, Carousel, Advert, FloorList, Partner, News } from '~components/home'
  19. import { Home } from '~components/mobile'
  20. export default {
  21. name: 'index',
  22. layout (context) {
  23. return context.store.state.option.isMobile ? 'mobile' : 'main'
  24. },
  25. components: {
  26. KindCategory,
  27. Carousel,
  28. Advert,
  29. FloorList,
  30. Partner,
  31. News,
  32. Home
  33. },
  34. fetch ({store}) {
  35. return !store.state.option.isMobile ? Promise.all([
  36. store.dispatch('loadFloors'),
  37. store.dispatch('loadBanners', {type: 'home'}),
  38. store.dispatch('loadProductKinds', { id: 0 }),
  39. store.dispatch('loadNewsSnapshot', { page: 1, pageSize: 10 })
  40. ]) : []
  41. },
  42. methods: {
  43. loadProductKinds (id) {
  44. this.$store.dispatch('loadAllProductKinds', {id})
  45. }
  46. },
  47. computed: {
  48. isMobile: function () {
  49. return this.$store.state.option.isMobile
  50. }
  51. }
  52. }
  53. </script>