• 博客园logo
  • 会员
  • 众包
  • 新闻
  • 博问
  • 闪存
  • 赞助商
  • HarmonyOS
  • Chat2DB
    • 搜索
      所有博客
    • 搜索
      当前博客
  • 写随笔 我的博客 短消息 简洁模式
    用户头像
    我的博客 我的园子 账号设置 会员中心 简洁模式 ... 退出登录
    注册 登录
车车大人
博客园    首页    新随笔    联系   管理     

Vue实现购物车库存加减

<template>
        <div>
              <!-- 数据列表 -->
            <div class="lines" v-for="(item,index) in info" :key="index">
                 <div class="img">
                     <img :src="item.goods_img" class="imgs">
                     
                 </div>
                 <div class="name">
                     商品名称:{{item.goods_name}}
                 </div>
                 <div class="desc">
                    简介:{{item.goods_desc}}            
                 </div>
                 <div class="price">
                     单价:¥{{item.goods_price}}                 
                 </div>
                 <div class="sum">
                     总价:¥{{item.c_price}}             
                 </div>
                 
                 <!-- 计数器 -->
                 <!-- <div class="counter"> -->
                     <el-input-number v-model="item.c_num" @change="handleChange(index)" :min="1" class="counter"></el-input-number>
                         <!-- <el-button type="info" icon="el-icon-minus" circle class="jian"></el-button>
                        <div><input type="text" v-model="num" value="item_c_num" class="num"></div>
                         <el-button type="info" icon="el-icon-plus" circle class="jia"></el-button> -->
                 <!-- </div> -->
                 
                 <div>
                      <el-button type="danger" icon="el-icon-delete" circle  class="del"></el-button>
                 </div>
                 
            </div>
        </div>
</template>


<script>
       export default {
          data() {
            return {
               info:[],
            };
          },
          methods:{
              handleChange(index) {
                        this.info[index].c_price =parseFloat(this.info[index].goods_price*this.info[index].c_num).toFixed(2)
                    }
          },
          created() {
                var obj = this
                this.$axios.get('/api/carinfo')
                .then(function(res){
                    obj.info = res.data.result
                    // console.log(res)
                })
          }
          
        }
</script>


<style>
    .lines{
        width: 80%;
        height: 170px;
        background-color: mintcream;
        float: left;
    }
    .img{
        width: 130px;
        height: 140px;
        background-color: antiquewhite;
        float: left;
        margin-top: 10px;
        margin-left: 10px;
    }
    .name{
        width: auto;
        height: 40px;
        float: left;
        margin-left: 10px;
        font-size: 16px;
        margin-top: 10px;
        line-height: 40px;
    }
    .desc{
        width: auto;
        
        height: 40px;
        margin-left: 150px;
        margin-top: 60px;
        font-size: 16px;
        line-height: 40px;
    }
    .price{
        width: 150px;
        height: 40px;
        margin-left: 150px;
        margin-top: 10px;
        font-size: 16px;
        line-height: 40px;
    }
    .sum{
        width: 150px;
        height: 40px;
        margin-left: 450px;
        margin-top: -90px;
        text-align: center;
        font-size:16px;
        line-height: 40px;
    }
    .counter{
        width: 160px;
        height: 50px;
        margin-left: 750px;
        float: left;
        margin-top: -43px;
    }
    .jian{
        width: 50px;
        height: 50px;
        float: left;
        background-color:#FAEBD7;
    }
    .jia{
        width: 50px;
        height: 50px;
        margin-left:0px;
        background-color:#FAEBD7;
    }
    .del{
        margin-right: 100px;
        width: 50px;
        height: 50px;
        float: right;
        margin-top: -50px;
    }
    .num{
        width: 55px;
        height: 45px;
        float: left;
    }
    .imgs{
        width: 100%;
        height

效果图:

 

通往牛逼的路上,在意的只有远方!
posted @ 2020-01-08 15:56  车车大人  阅读(1364)  评论(0)    收藏  举报
刷新页面返回顶部
博客园  ©  2004-2025
浙公网安备 33010602011771号 浙ICP备2021040463号-3