list.vue 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. <!-- @format -->
  2. <script lang="ts" setup>
  3. import templateTwo from './comp/temp2.vue'
  4. import templateOne from './comp/temp1.vue'
  5. import { Api } from '@/api/model/url'
  6. const categoryList = ref<any>([])
  7. const list_column_one = ref<any>([])
  8. const list_column_two = ref<any>([])
  9. const list_column_three = ref<any>([])
  10. const requestUrl = `${process.env.MY_ENV_DEV_URL}${Api.CategoryList}`
  11. const { data, pending, error, refresh } = await useAsyncData(
  12. 'category-catalogue',
  13. () => $fetch(`${requestUrl}`, { params: { all: true } }),
  14. )
  15. categoryList.value = data.value?.result || []
  16. // 获取categoryList的前3个元素给到list_column_one,并且不改变原数组categoryList
  17. list_column_one.value = categoryList.value.slice(0, 3)
  18. list_column_two.value = categoryList.value.slice(3, 5)
  19. list_column_three.value = categoryList.value.slice(5, 8)
  20. console.log('categoryList', categoryList.value, list_column_one.value, list_column_two.value, list_column_three.value)
  21. </script>
  22. <template>
  23. <div class="bg-#fff py-120px">
  24. <div class="w-1200-auto text-center">
  25. <h2 class="text-36px fw-800 text-#333 !mb-20px custom-title-font">
  26. Access Category-Driven <span class="custom-title-bg">Solutions</span>
  27. </h2>
  28. <div class="text-#999 text-22px mb-80px">
  29. For viral-ready, trend-optimized products - Ready to download!
  30. </div>
  31. <div class="flex gap-40px text-left">
  32. <div class="flex flex-col gap-40px flex-1">
  33. <div v-for="(item, index) in list_column_one" :key="index">
  34. <template-one v-if="index % 2 === 0" :item />
  35. <template-two v-else :item />
  36. </div>
  37. </div>
  38. <div class="flex flex-col gap-40px flex-1">
  39. <div v-for="(item, index) in list_column_two" :key="index">
  40. <template-two :item />
  41. </div>
  42. </div>
  43. <div class="flex flex-col gap-40px flex-1">
  44. <div v-for="(item, index) in list_column_three" :key="index">
  45. <template-one v-if="index % 2 === 0" :item />
  46. <template-two v-else :item />
  47. </div>
  48. </div>
  49. </div>
  50. </div>
  51. </div>
  52. </template>
  53. <style lang="less" scoped>
  54. </style>