Bläddra i källkod

修改首页加入购物车,如果去跳转使用公用方法

skyblued 3 år sedan
förälder
incheckning
953eac278b

+ 1 - 1
src/views/shop-mall/components/tab-list/index.tsx

@@ -161,7 +161,7 @@ export default defineComponent({
             this.addGoodsShow = false
           }}
         >
-          <AddGoodsCart item={this.selectGoodsItem} />
+          <AddGoodsCart item={this.selectGoodsItem} onOpenWebView={this.onOpenWebView} />
         </Popup>
       </div>
     )

+ 13 - 4
src/views/shop-mall/modal/add-goods-cart/index.tsx

@@ -26,6 +26,10 @@ export default defineComponent({
     defaultRadio: {
       type: Number,
       default: 0
+    },
+    onOpenWebView: {
+      type: Function,
+      default: (n: any) => {}
     }
   },
   data() {
@@ -96,7 +100,7 @@ export default defineComponent({
         price: selectItem.price, //添加到购物车的价格
         productSkuId: selectItem.id,
         quantity: this.total, // 数量
-        productId: item.id,
+        productId: item.id
       }
       // console.log(body)
       try {
@@ -112,10 +116,15 @@ export default defineComponent({
             confirmButtonColor: 'var(--van-primary)'
           })
             .then(() => {
+              // 如果为首页加入购物车跳转, 使用首页的公用跳转方法
+              if (this.onOpenWebView.toString() === 'n => {}') {
+                this.$router.push({
+                  path: '/cart'
+                })
+              } else {
+                this.onOpenWebView('/cart')
+              }
               // on confirm
-              this.$router.push({
-                path: '/cart'
-              })
             })
             .catch(() => {
               // on cancel