From 9d8e0d507b2fd2310681e073c19b0ff87b39a065 Mon Sep 17 00:00:00 2001 From: puhui999 Date: Wed, 7 Jun 2023 08:59:03 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E6=95=B0=E7=BB=84=E6=93=8D=E4=BD=9C?= =?UTF-8?q?=E6=B7=BB=E5=8A=A0=20=3F=20=E5=8F=AF=E9=80=89=E6=93=8D=E4=BD=9C?= =?UTF-8?q?=E7=AC=A6=EF=BC=8C=E9=81=BF=E5=85=8D=E5=B1=9E=E6=80=A7=E5=80=BC?= =?UTF-8?q?=E4=B8=BA=20null=20=E6=97=B6=E6=8A=A5=E9=94=99?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit (cherry picked from commit 20f3f7267023b21fc28541ed7a0f35f3a0d3e832) --- src/views/mall/product/spu/addForm.vue | 2 +- .../mall/product/spu/components/BasicInfoForm.vue | 14 +++++++------- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/src/views/mall/product/spu/addForm.vue b/src/views/mall/product/spu/addForm.vue index 2d5a3528..7d91d857 100644 --- a/src/views/mall/product/spu/addForm.vue +++ b/src/views/mall/product/spu/addForm.vue @@ -104,7 +104,7 @@ const getDetail = async () => { formLoading.value = true try { const res = (await ProductSpuApi.getSpu(id)) as ProductSpuApi.Spu - res.skus!.forEach((item) => { + res.skus?.forEach((item) => { // 回显价格分转元 item.price = formatToFraction(item.price) item.marketPrice = formatToFraction(item.marketPrice) diff --git a/src/views/mall/product/spu/components/BasicInfoForm.vue b/src/views/mall/product/spu/components/BasicInfoForm.vue index c3ccf6b5..7b122151 100644 --- a/src/views/mall/product/spu/components/BasicInfoForm.vue +++ b/src/views/mall/product/spu/components/BasicInfoForm.vue @@ -256,7 +256,7 @@ watch( return } copyValueToTarget(formData, data) - formData.sliderPicUrls = data['sliderPicUrls'].map((item) => ({ + formData.sliderPicUrls = data['sliderPicUrls']?.map((item) => ({ url: item })) // 只有是多规格才处理 @@ -265,16 +265,16 @@ watch( } // 直接拿返回的 skus 属性逆向生成出 propertyList const properties = [] - formData.skus.forEach((sku) => { - sku.properties.forEach(({ propertyId, propertyName, valueId, valueName }) => { + formData.skus?.forEach((sku) => { + sku.properties?.forEach(({ propertyId, propertyName, valueId, valueName }) => { // 添加属性 - if (!properties.some((item) => item.id === propertyId)) { + if (!properties?.some((item) => item.id === propertyId)) { properties.push({ id: propertyId, name: propertyName, values: [] }) } // 添加属性值 - const index = properties.findIndex((item) => item.id === propertyId) - if (!properties[index].values.some((value) => value.id === valueId)) { - properties[index].values.push({ id: valueId, name: valueName }) + const index = properties?.findIndex((item) => item.id === propertyId) + if (!properties[index].values?.some((value) => value.id === valueId)) { + properties[index].values?.push({ id: valueId, name: valueName }) } }) })