优化壁纸分类组件数据获取逻辑
This commit is contained in:
@ -84,7 +84,7 @@
|
||||
})
|
||||
|
||||
/** 版本 */
|
||||
const { data: editionsList } = useAsyncData(`editionsList-${props.type}-${Date.now()}`, async () => {
|
||||
const { data: editionsList } = useAsyncData(`editionsList-${props.type}}`, async () => {
|
||||
const res = await parent({ type: 2, parentId: 0 })
|
||||
const all = [{ id: '-1', name: '全部' }]
|
||||
return [...all, ...res.data]
|
||||
@ -92,7 +92,7 @@
|
||||
|
||||
// 获取面包屑
|
||||
const { data: breadList } = await useAsyncData(
|
||||
`breadList-${props.type}-${props.id}-${query.value.projectType}-${Date.now()}`,
|
||||
`breadList-${props.type}-${props.id}-${query.value.projectType}}`,
|
||||
async () => {
|
||||
const res = await getDictTree({ type: 1, id: query.value.projectType })
|
||||
const all = [
|
||||
@ -104,13 +104,8 @@
|
||||
]
|
||||
const arr = [...res.data, ...all]
|
||||
return arr.reverse()
|
||||
},
|
||||
{
|
||||
immediate: true,
|
||||
}
|
||||
)
|
||||
|
||||
console.log('breadList', breadList);
|
||||
|
||||
// const projectTypeList = ref<any>([])
|
||||
/** 获取分类下拉框 */
|
||||
@ -140,7 +135,7 @@
|
||||
// }
|
||||
// getEditionsList()
|
||||
|
||||
console.log('breadList.value.length----', breadList.value?.length);
|
||||
console.log('breadList.value.length----', breadList.value);
|
||||
|
||||
// 服务端渲染兼容方案:顺序执行异步操作
|
||||
// 1. 先获取面包屑数据(已在上面通过useAsyncData获取)
|
||||
@ -160,6 +155,9 @@
|
||||
parentId = breadList?.value[length - 1].id
|
||||
}
|
||||
}
|
||||
|
||||
console.log('parentId', parentId);
|
||||
|
||||
|
||||
try {
|
||||
// 获取分类数据
|
||||
@ -174,7 +172,7 @@
|
||||
|
||||
// 使用useAsyncData获取分类列表,确保服务端渲染兼容性
|
||||
const { data: projectTypeList } = await useAsyncData(
|
||||
`projectType-draw-${props.type}-${query.value.projectType}-${Date.now()}`,
|
||||
`projectType-draw-${props.type}-${query.value.projectType}}`,
|
||||
getProjectTypeList,
|
||||
{ server: true } // 确保在服务端执行
|
||||
)
|
||||
|
||||
Reference in New Issue
Block a user