sanmu
authored
2 years ago
1
2
<script setup lang="ts">
import { onMounted, watchEffect, toValue } from 'vue'
sanmu
authored
2 years ago
3
import { RouterView } from 'vue-router'
sanmu
authored
2 years ago
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
2 years ago
8
9
import { isMobile } from './utils'
import MobileHeader from './components/MobileHeader.vue'
sanmu
authored
2 years ago
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
2 years ago
28
29
<Header v-if="!isMobile()" />
<MobileHeader v-if="isMobile()" />
sanmu
authored
2 years ago
30
sanmu
authored
2 years ago
31
<div class="tw-min-h-[700px]">
sanmu
authored
2 years ago
32
33
34
<KeepAlive>
<RouterView />
</KeepAlive>
sanmu
authored
2 years ago
35
36
37
</div>
<Footer />
</template>