v-if跟v-show
写这个区域的时候,因为没有商品就自动隐藏,需要做一个边界的判断

我想的是这里回频繁切换,我就使用了v-show 但是 会波浪线提示

换成v-if就没事

请问这个是什么现象
按理说这两个都是一样的把?只是如果频繁切换的话才需要使用 v-show
(v-if 会操作dom,v-show会使用display)
代码如下:
<template>
<div class="cart">
<div class="product">
<div class="product__item" v-for="item in productList" :key="item._id">
<template v-if="item.count > 0">
<img class="product__item__img" :src="item.imgUrl" />
<div class="product__item__detail">
<h4 class="product__item__title">{{ item.name }}</h4>
<p class="product__item__price">
<span class="product__item__yen">¥{{ item.price }}</span>
<span class="product__item__origin">¥{{ item.oldPrice }}</span>
</p>
</div>
<div class="product__number">
<span
class="product__number__minus iconfont"
@click="
() => {
changeCartItemInfo(shopId, item._id, item, -1);
}
"
></span
>
{{ item.count || 0 }}
<span
class="product__number__plus iconfont"
@click="
() => {
changeCartItemInfo(shopId, item._id, item, 1);
}
"
></span
>
</div>
</template>
</div>
</div>
<div class="check">
<div class="check__icon">
<img
class="check__icon__img"
src="http://www.dell-lee.com/imgs/vue3/basket.png"
/>
<div class="check__icon__tag">{{ total }}</div>
</div>
<div class="check__info">
总计:<span class="check__info__price">¥{{ price }}</span>
</div>
<div class="check__btn">去结算</div>
</div>
</div>
</template>
<script>
import { computed } from "vue";
import { useStore } from "vuex";
import { useRoute } from "vue-router";
import { useCommonCartEffect } from "./commonCartEffect";
//获取购物车信息逻辑
const useCartEffect = (shopId) => {
const store = useStore();
const cartList = store.state.cartList;
//计算 Tab 栏数量
const total = computed(() => {
const productList = cartList[shopId];
let count = 0;
if (productList) {
for (let i in productList) {
const product = productList[i];
count += product.count;
}
}
return count;
});
//计算 Tab 栏 价格
const price = computed(() => {
const productList = cartList[shopId];
let count = 0;
if (productList) {
for (let i in productList) {
const product = productList[i];
count += product.count * product.price;
}
}
return count.toFixed(2);
});
const productList = computed(() => {
const productList = cartList[shopId] || [];
return productList;
});
return { total, price, productList, cartList };
};
export default {
name: "Cart",
setup() {
const route = useRoute();
const shopId = route.params.id;
const { changeCartItemInfo } = useCommonCartEffect();
const { total, price, productList, cartList } = useCartEffect(shopId);
return { total, price, productList, shopId, cartList, changeCartItemInfo };
},
};
</script>
<style lang="scss" scoped>
@import "../../style/variables.scss";
@import "../../style/mixins.scss";
.cart {
position: absolute;
left: 0;
right: 0;
bottom: 0;
}
.product {
overflow-y: scroll;
flex: 1;
background: #fff;
&__item {
position: relative;
display: flex;
padding: 0.12rem 0;
margin: 0 0.16rem;
border-bottom: 0.01rem solid $content-bgColor;
&__img {
width: 0.46rem;
height: 0.46rem;
margin-right: 0.16rem;
}
&__title {
margin: 0;
line-height: 0.2rem;
font-size: 0.14rem;
color: $content-fontColor;
@include ellipsis;
}
&__price {
margin-top: 0.06rem;
line-height: 0.2rem;
font-size: 0.14rem;
color: $hightLight-fontColor;
}
&__yen {
font-size: 0.12rem;
font-weight: bold;
}
&__origin {
margin-left: 0.08rem;
line-height: 0.2rem;
font-size: 0.12rem;
color: $light-fontColor;
text-decoration: line-through;
}
.product__number {
position: absolute;
right: 0;
bottom: 0.12rem;
&__minus,
&__plus {
display: inline-block;
width: 0.2rem;
line-height: 0.2rem;
border-radius: 50%;
font-size: 0.18rem;
text-align: center;
}
&__minus {
border: 0.01rem solid $medium-fontColor;
color: $medium-fontColor;
margin-right: 0.05rem;
}
&__plus {
background: $btn-bgColor;
color: $bgColor;
margin-left: 0.05rem;
}
}
}
}
.check {
display: flex;
line-height: 0.5rem;
box-sizing: border-box;
border-top: 0.01rem solid $content-bgColor;
&__icon {
position: relative;
width: 0.84rem;
&__img {
display: block;
margin: 0.12rem auto;
width: 0.28rem;
height: 0.26rem;
}
&__tag {
position: absolute;
left: 0.49rem;
top: 0.04rem;
padding: 0 0.04rem;
min-width: 0.15rem;
height: 0.15rem;
line-height: 0.15rem;
background-color: $hightLight-fontColor;
color: #fff;
border-radius: 0.1rem;
text-align: center;
}
}
&__info {
flex: 1;
color: $content-fontColor;
font-size: 0.12rem;
&__price {
color: $hightLight-fontColor;
font-size: 0.18rem;
}
}
&__btn {
width: 0.98rem;
text-align: center;
background-color: #4fb0f9;
color: #fff;
font-size: 0.14rem;
}
}
</style>8
收起
正在回答 回答被采纳积分+1
1回答
恭喜解决一个难题,获得1积分~
来为老师/同学的回答评分吧
0 星