老师代码报错啊

老师代码报错啊

<template >

  <div class="cart">

    <div class="product">


      <div class="product_item" v-for="item in productList" :key="item._id">

        <img class="product_item_img" :src="item.imgurl" alt="" />

        <div class="product_item_detail">

          <h4 class="product_item_title">{{ item.name }}</h4>

         

          <p class="product_item_price">

            <span class="product_item_yen">&yen;</span>{{ item.price }}

            <span class="product_item_origin">&yen;{{ item.oldprice }}</span>

          </p>

        </div>

        <div class="product_number">

          <span

            class="product_number_minus"

            @click="()=>{changeCartiteminfo(shopid,item_.id, item,-1 )}"

            >-</span

          >

          {{ item.count || 0 }}

          <span

            class="product_number_plus"

            @click="()=>{changeCartiteminfo(shopid,item_.id ,item,1 )}"

            >+</span

          >

        </div>

      </div>

    </div>

    <div class="check">

      <div class="check_icon">

        <img

          src="http://www.dell-lee.com/imgs/vue3/basket .png"

          alt=""

          class="check_icon_img"

        />

        <div class="check_icon_tag">{{ total }}</div>

      </div>

      <div class="check_info">

        总计<span class="check_info_price">&yen; {{ price }}</span>

      </div>

      <div class="check_btn">去结算</div>

    </div>

  </div>

</template>

<script>

import { computed } from "vue";

import { useRoute } from "vue-router";

import { useStore } from "vuex";

const useCartEffect = (shopid) => {

  const store = useStore();

 

  const cartList = store.state.cartList;


  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;

  }


  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,};

};


export default {

  name: "cart",

  setup() {

    const route = useRoute();

    const shopid = route.params.id;

    const { total, price,productList, } = useCartEffect(shopid );

    return { total, price,productList,};

  },

};

</script>

<style lang="scss" scopd>

@import "../../style/viriables.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;

    &_detail {

      overflow: hidden;

    }

    &_img {

      width: .46rem;

      height: .46rem;

      margin-right: 0.16rem;

    }

    &_title {

      margin: 0;

      line-height: 0.2rem;

      font-size: 0.14rem;

      color: $content-fontcolor;

      @include ellipsis;

    }

 

    &_price {

      margin:  .06rem 0 0 0;

      margin: 0;

      line-height: 0.2rem;

      font-size: 0.14rem;

      color: $highlight-fontColor;

    }

    &_yen {

      font-size: 0.12rem;

    }

    &_origin {

      margin-left: 0.06rem;

      line-height: 0.2rem;

      font-size: 0.12rem;

      color: $linght-fontColor;

      text-decoration: line-through;

    }

    .product_number {

      position: absolute;

      right: 0;

      bottom: 0.12rem;

      &_minus,

      &_plus {

        display: inline-block;

        width: 0.2rem;

        height: 0.2rem;

        line-height: 0.16rem;

        border-radius: 50%;

        border: 0.01rem solid #666;

        font-size: 0.2rem;

        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 {

  // box-sizing: border-box;

  line-height: 0.49rem;

  display: flex;

  height: 0.49rem;

  border-top: 01rem solid $content-bgColor;

  &_icon {

    width: 0.84rem;

    position: relative;

    &_img {

      display: block;

      margin: 0.12rem auto;

      width: 0.28rem;

      height: 0.26rem;

    }

    &_tag {

      position: absolute;

      left: 0.46rem;

      top: 0.04rem;

      right: 0.2rem;

      padding: 0 0.04rem;

      min-width: 0.2rem;

      height: 0.2rem;

      line-height: 0.2rem;

      background-color: $highlight-fontColor;

      border-radius: 0.1rem;

      font-size: 0.12rem;

      text-align: center;

      color: #fff;

      transform: scale(0.5);

      transform-origin: left center;

    }

  }

  &_info {

    flex: 1;

    color: $content-fontcolor;

    font-size: 0.12rem;

    &_price {

      line-height: 0.49rem;

      color: $highlight-fontColor;

      font-size: 0.18rem;

    }

  }

  &_btn {

    width: 0.98rem;

    background-color: #4fb0f9;

    color: #fff;

    text-align: center;

    font-size: 0.14rem;

  }

}


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

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

1回答
好帮手慕星星 2022-11-08 11:32:09

同学你好,代码问题如下:

1、图片属性名大小写错误,参考修改

https://img1.sycdn.imooc.com//climg/6369cce4090e811609030118.jpg

2、购物车图片名称中多余的空格去掉

https://img1.sycdn.imooc.com//climg/6369cd11098474c610720125.jpg

3、计算属性闭合符号需要对应,并且需要获取productList属性

https://img1.sycdn.imooc.com//climg/6369cd3d09daf21707070520.jpg

4、返回内容要在计算属性中

https://img1.sycdn.imooc.com//climg/6369cd5e09d79e6107110590.jpg

5、去掉多余的逗号

https://img1.sycdn.imooc.com//climg/6369cd7a0912bb7a06890337.jpg

https://img1.sycdn.imooc.com//climg/6369cd8a09e326e208790449.jpg

6、scpoed属性拼接错误,并且在引入地址后加分号

https://img1.sycdn.imooc.com//climg/6369cdad0937ac1106280228.jpg

https://img1.sycdn.imooc.com//climg/6369ecfc09bf647f05720326.jpg

修改后的效果:

https://img1.sycdn.imooc.com//climg/6369cdb60971b2af04080330.jpg

祝学习愉快!


  • 提问者 球球不一般 #1

    https://img1.sycdn.imooc.com//climg/6369ec8f098ee58711920970.jpg

    2022-11-08 13:43:45
  • 提问者 球球不一般 #2

    <template >

      <div class="cart">

        <div class="product">

          <template v-for="item in productList" :key="item._id">

            <div class="product_item" v-if="item.count">

              0">

              <img class="product_item_img" :src="item.imgUrl" alt="" />

              <div class="product_item_detail">

                <h4 class="product_item_title">{{ item.name }}</h4>


                <p class="product_item_price">

                  <span class="product_item_yen">&yen;</span>{{ item.price }}

                  <span class="product_item_origin">&yen;{{ item.oldprice }}</span>

                </p>

              </div>

              <div class="product_number">

                <span

                  class="product_number_minus"

                  @click="

                    () => {

                      changeCartiteminfo(shopid, item_.id, item, -1);

                    }

                  "

                  >-</span

                >

                {{ item.count || 0 }}

                <span

                  class="product_number_plus"

                  @click="

                    () => {

                      changeCartiteminfo(shopid, item_.id, item, 1);

                    }

                  "

                  >+</span

                >

              </div>

            </div>

          </template>

        </div>

        <div class="check">

          <div class="check_icon">

            <img

              src="http://www.dell-lee.com/imgs/vue3/basket.png"

              alt=""

              class="check_icon_img"

            />

            <div class="check_icon_tag">{{ total }}</div>

          </div>

          <div class="check_info">

            总计<span class="check_info_price">&yen; {{ price }}</span>

          </div>

          <div class="check_btn">去结算</div>

        </div>

      </div>

    </template>


    2022-11-08 13:44:09
  • 提问者 球球不一般 #3

    <script>

    import { computed } from "vue";

    import { useRoute } from "vue-router";

    import { useStore } from "vuex";

    import {  useCommonCartEffect} from './commonCartEffect';

    const useCartEffect = (shopid) => {

      const store = useStore();

     

      const cartList = store.state.cartList;


      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;

      })


      const price = computed(() => {

        const productList = cartList[shopid].productList;

        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].productList||[]

    return productList

      })

      return { total, price ,productList};

    };


    export default {

      name: "cart",

      setup() {

        const route = useRoute();

        const shopid = route.params.id;

        const{changeCartiteminfo}=useCommonCartEffect()

        const { total, price,productList } = useCartEffect(shopid );

        return { total, price,productList,changeCartiteminfo,shopid};

      },

    };

    </script>


    2022-11-08 13:44:33
问题已解决,确定采纳
还有疑问,暂不采纳

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

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

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

在线咨询

领取优惠

免费试听

领取大纲

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