浏览代码

没有历史记录则跳转商城

lifanagju_citu 4 月之前
父节点
当前提交
93954063e3
共有 2 个文件被更改,包括 10 次插入5 次删除
  1. 4 4
      src/views/mall/components/GoodsItem/index.vue
  2. 6 1
      src/views/mall/components/details.vue

+ 4 - 4
src/views/mall/components/GoodsItem/index.vue

@@ -19,7 +19,7 @@
 
 <script setup>
 defineOptions({ name: 'mall-goods-item'})
-import { useRouter } from 'vue-router'
+// import { useRouter } from 'vue-router'
 import { fen2yuan } from '@/hooks/web/useGoods'
 
 defineProps({ 
@@ -41,12 +41,12 @@ defineProps({
   }
 })
 
-const router = useRouter()
+// const router = useRouter()
 
 const handleDetail = (val) => {
   const spuId = val.spuId || val.id // 商品id
-  // window.open(`/mall/goodsDetail/${spuId}`)
- if (spuId) router.push(`/mall/goodsDetail/${spuId}`)
+  if (spuId) window.open(`/mall/goodsDetail/${spuId}`)
+  // if (spuId) router.push(`/mall/goodsDetail/${spuId}`)
 }
 </script>
 

+ 6 - 1
src/views/mall/components/details.vue

@@ -4,7 +4,7 @@
   <!-- <Navbar /> -->
   <div class="default-width pb-5 mt-3 pt-3" v-if="state.goodsInfo && Object.keys(state.goodsInfo).length">
     <v-card class="carousel border-radius-8 white-bgc pa-5" style="width: 100%;">
-      <v-btn variant="text" size="x-large" prepend-icon="mdi-chevron-triple-left" color="primary" @click.stop="router.go(-1)">返回</v-btn>
+      <v-btn variant="text" size="x-large" prepend-icon="mdi-chevron-triple-left" color="primary" @click.stop="goBack">返回</v-btn>
       <div class="mt-1 d-flex">
         <!-- 图片展示-轮播 -->
         <div style="width: 400px; height: 400px;">
@@ -212,6 +212,11 @@ const loginClose = () => {
   Snackbar.warning('您已取消登录')
 }
 
+const goBack = () => {
+  router.history?.length ? router.go(-1) : router.push('/mall')
+  // router.go(-1)
+}
+
 </script>
 
 <style lang="scss" scoped>