list.vue 2.2 KB

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