shopName 不显示
相关代码:
<template>
<div class="wrapper">相关代码:
<div class="top">
<div class="top__header">
<div class="iconfont top__header__back"></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"></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">¥ </span>
{{ item.price }} x {{ item.count }}
</span>
<span class="products__item__total">
<span class="products__item__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 };
};相关截图:

问题描述:
老师你好,我这边沃尔玛不显示,请问是怎么回事
24
收起
正在回答 回答被采纳积分+1
2回答
好帮手慕然然
2021-11-11 18:08:03
同学你好,老师这边测试同学的代码是没问题的,可以显示shopName,建议同学按照以下思路排查一下问题:在OrderConfirmation.vue文件中,打印一下shopName,看打印结果是否正确,如图

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

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


恭喜解决一个难题,获得1积分~
来为老师/同学的回答评分吧
0 星