|
@@ -22,7 +22,7 @@
|
|
|
|
|
|
<script setup>
|
|
|
defineOptions({ name: 'mall-home-hotGoods'})
|
|
|
-import { ref, computed } from 'vue'
|
|
|
+import { ref, computed, watch } from 'vue'
|
|
|
import { getProductByIds } from '@/api/mall/index'
|
|
|
import { formatSales, fen2yuan } from '@/hooks/web/useGoods'
|
|
|
import { isArray } from 'lodash-es'
|
|
@@ -33,15 +33,22 @@ const router = useRouter()
|
|
|
|
|
|
// 根据id获取商品列表
|
|
|
const goodList = ref([])
|
|
|
-const getGoodsList = async () => {
|
|
|
- const productCard = props.templateData?.home?.components.find(item => item.id === 'ProductCard')
|
|
|
+const getGoodsList = async (val) => {
|
|
|
+ const productCard = val?.home?.components.find(item => item.id === 'ProductCard')
|
|
|
if (!productCard) return
|
|
|
const ids = productCard.property.spuIds
|
|
|
if (!ids.length) return
|
|
|
const data = await getProductByIds(ids)
|
|
|
goodList.value = data
|
|
|
}
|
|
|
-getGoodsList()
|
|
|
+
|
|
|
+watch(
|
|
|
+ () => props.templateData,
|
|
|
+ async (val) => {
|
|
|
+ await getGoodsList(val)
|
|
|
+ },
|
|
|
+ { immediate: true, deep: true }
|
|
|
+)
|
|
|
|
|
|
// 格式化销量、库存信息
|
|
|
const salesAndStock = computed(() => (data) => {
|