shopName 不显示

shopName 不显示

相关代码:

<template>
  <div class="wrapper">相关代码:
    <div class="top">
      <div class="top__header">
        <div class="iconfont top__header__back">&#xe6f2;</div>
        确认订单
      </div>
      <div class="top__receiver">
        <div class="top__receiver__title">收货地址</div>
        <div class="top__receiver__address">
          北京理工大学国防科技园2号楼10层
        </div>
        <div class="top__receiver__info">
          <span class="top__receiver__info__name">瑶妹(先生)</span>
          <span class="top__receiver__info__name">18911024266</span>
        </div>
        <div class="iconfont top__receiver__icon">&#xe6f2;</div>
      </div>
    </div>

    <div class="products">
      <div class="products__title">{{ shopName }}</div>
      <div class="products__list">
        <div class="products__item" v-for="item in productList" :key="item._id">
          <img class="products__item__img" :src="item.imgUrl" />
          <div class="products__item__detail">
            <h4 class="products__item__title">{{ item.name }}</h4>
            <p class="products__item__price">
              <span>
                <span class="products__item__yen">&yen; </span>
                {{ item.price }} x {{ item.count }}
              </span>
              <span class="products__item__total">
                <span class="products__item__yen">&yen; </span>
                {{ item.price * item.count }}
              </span>
            </p>
          </div>
        </div>
      </div>
    </div>
  </div>
</template>

<script>
import { useRoute } from "vue-router";
import { useCommonCartEffect } from "../../effects/cartEffects";
export default {
  name: "OrderConfirmation",
  setup() {
    const route = useRoute();
    const shopId = route.params.id;
    const { shopName, productList } = useCommonCartEffect(shopId);
    return { shopName, productList };
  },
};
</script>

<style lang="scss" scoped>
@import "../../style/viriables.scss";
@import "../../style/mixins.scss";
.wrapper {
  position: absolute;
  left: 0;
  right: 0;
  top: 0;
  bottom: 0;
  background-color: #eee;
}
.top {
  position: relative;
  height: 1.96rem;
  background-size: 100% 1.59rem;
  background-image: linear-gradient(0deg, rgba(0, 145, 255, 0) 4%, #0091ff 50%);
  background-repeat: no-repeat;
  &__header {
    position: relative;
    padding-top: 0.26rem;
    line-height: 0.24rem;
    color: #fff;
    text-align: center;
    font-size: 0.16rem;
    &__back {
      position: absolute;
      left: 0.18rem;
      font-size: 0.22rem;
    }
  }
  &__receiver {
    position: absolute;
    left: 0.18rem;
    right: 0.18rem;
    bottom: 0;
    height: 1.11rem;
    background: #fff;
    border-radius: 0.04rem;
    &__title {
      line-height: 0.22rem;
      padding: 0.16rem 0 0.14rem 0.16rem;
      font-size: 0.16rem;
      color: #333;
    }
    &__address {
      line-height: 0.2rem;
      padding: 0 0.4rem 0 0.16rem;
      font-size: 0.14rem;
      color: #333;
    }
    &__info {
      padding: 0.06rem 0 0 0.16rem;
      &__name {
        margin-right: 0.06rem;
        line-height: 0.18rem;
        font-size: 0.12rem;
        color: #666;
      }
    }
    &__icon {
      transform: rotate(180deg);
      position: absolute;
      right: 0.16rem;
      top: 0.5rem;
      color: #666;
      font-size: 0.2rem;
    }
  }
}
.products {
  margin: 0.16rem 0.18rem 0.55rem 0.18rem;
  background: #fff;
  &__title {
    padding: 0.16rem 0.16rem 0 0.16rem;
    font-size: 0.16rem;
    color: #333;
  }
  &__item {
    position: relative;
    display: flex;
    padding: 0.16rem;
    &__img {
      width: 0.46rem;
      height: 0.46rem;
      margin-right: 0.16rem;
    }
    &__detail {
      flex: 1;
    }
    &__title {
      margin: 0;
      line-height: 0.2rem;
      font-size: 0.14rem;
      color: $content-fontcolor;
      @include ellipsis;
    }
    &__price {
      display: flex;
      margin: 0.06rem 0 0 0;
      line-height: 0.2rem;
      font-size: 0.14rem;
      color: $hightlight-fontColor;
    }
    &__total {
      flex: 1;
      text-align: right;
      color: #000;
    }
    &__yen {
      font-size: 0.12rem;
    }
  }
}
</style>

相关代码:

// 购物车相关逻辑
import { computed } from "vue";
import { useStore } from "vuex";
export const useCommonCartEffect = (shopId) => {
  const store = useStore();
  const cartList = store.state.cartList;
  const changeCartItemInfo = (shopId, productId, productInfo, num) => {
    store.commit("changeCartItemInfo", {
      shopId,
      productId,
      productInfo,
      num,
    });
  };

  const productList = computed(() => {
    const productList = cartList[shopId]?.productList || [];
    return productList;
  });
  const shopName = computed(() => {
    const shopName = cartList[shopId]?.shopName || "";
    return shopName;
  });
  return { cartList, shopName, productList, changeCartItemInfo };
};


相关截图:

https://img1.sycdn.imooc.com//climg/618cd435090e8d9104320367.jpg

问题描述:

老师你好,我这边沃尔玛不显示,请问是怎么回事

正在回答 回答被采纳积分+1

登陆购买课程后可参与讨论,去登陆

2回答
好帮手慕久久 2021-11-12 13:53:09

同学你好,从打印的数据上来看,第一组数据中没有shopName,此时如果渲染第一组数据,就可能不显示shopName。

由于问题特殊,建议同学查看一下私信:

https://img1.sycdn.imooc.com//climg/618dfd66095a560912880216.jpg

祝学习愉快!

好帮手慕然然 2021-11-11 18:08:03

同学你好,老师这边测试同学的代码是没问题的,可以显示shopName,建议同学按照以下思路排查一下问题:在OrderConfirmation.vue文件中,打印一下shopName,看打印结果是否正确,如图

https://img1.sycdn.imooc.com//climg/618ce8cc09739ede17620630.jpg

如果不正确的话,就向上查找shopName的来源,即useCommonCartEffect方法(位于cartEffects.js中),在该方法中shopName由计算属性得到,在该计算属性中,分别打印一下shopName、cartList以及shopId,查看打印结果是否是预期的,如图

https://img1.sycdn.imooc.com//climg/618ce9f509081d1517530568.jpg

如果shopName显示不正确的话,cartList和shopId应该有一个存在问题,具体是哪个,同学需要看自己的控制台,如果是cartList存在问题,需要向上查看cartList的来源,即store.state.cartList,如果是shopId存在问题,需要向上查看shopId的来源,即调用changeCartItemInfo方法时传入的shopId,这里涉及的代码比较多,建议同学按照上面的思路,先试着一层层向上排查一下。

祝学习愉快!

  • 提问者 以你为瘾丶 #1

    https://img1.sycdn.imooc.com//climg/618cf9de09e3403604720160.jpg

    请问这个是错哪了,

    2021-11-11 19:09:29
问题已解决,确定采纳
还有疑问,暂不采纳

恭喜解决一个难题,获得1积分~

来为老师/同学的回答评分吧

0 星

相似问题

登录后可查看更多问答,登录/注册

请稍等 ...
意见反馈 帮助中心 APP下载
官方微信

在线咨询

领取优惠

免费试听

领取大纲

扫描二维码,添加
你的专属老师