Blame view

src/App.vue 960 Bytes
sanmu authored
1
2
<script setup lang="ts">
import { onMounted, watchEffect, toValue } from 'vue'
sanmu authored
3
import { RouterView } from 'vue-router'
sanmu authored
4
5
6
7
import Header from '@/components/Header.vue'
import Footer from '@/components/Footer.vue'
import { useCategoryStore } from './stores/category'
import { useProductListStore } from './stores/product_list'
sanmu authored
8
9
import { isMobile } from './utils'
import MobileHeader from './components/MobileHeader.vue'
sanmu authored
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27

const categoryStore = useCategoryStore()
const productListStore = useProductListStore()

onMounted(() => {
  // 请求分类列表
  categoryStore.getList()
})

watchEffect(() => {
  if (toValue(categoryStore?.list)) {
    const cId = categoryStore?.list?.[0]?.list?.[0]?.id
    if (cId) productListStore.updateCategory(cId)
  }
})
</script>

<template>
sanmu authored
28
29
  <Header v-if="!isMobile()" />
  <MobileHeader v-if="isMobile()" />
sanmu authored
30
sanmu authored
31
  <div class="tw-min-h-[700px]">
sanmu authored
32
33
34
    <KeepAlive>
      <RouterView />
    </KeepAlive>
sanmu authored
35
36
37
  </div>
  <Footer />
</template>