首页 > 其他 > 详细

VUE + ElementUI VUE双向绑定实现购物车开发

时间:2020-05-29 12:42:22      阅读:433      评论:0      收藏:0      [点我收藏+]
<template>
    <div>
        <el-table :data=productList>
            <el-table-column label="图片">
                <template slot-scope="scope">
                    <img v-bind:src="scope.row.img" height="80px;"/>
                </template>
            </el-table-column>
            <el-table-column label="信息">
                <template slot-scope="scope">
                    <h3>{{scope.row.name}}</h3>
                    <h4>{{scope.row.price}}</h4>
                    <!-- <input  v-model="scope.row.num" /> -->
                    <!-- <el-input v-model="scope.row.num"></el-input> -->
                    <el-input-number v-model="scope.row.num" @change="handleChange" :min="1" :max="10" label="描述文字"></el-input-number>
                </template>
            </el-table-column>
        </el-table>
        <div>
            总价:{{total}}
            <el-button type="primary">结算</el-button>
        </div>
    </div>
</template>

<script>
    export default {
        data(){
            return {
                total:0,
                productList:[{id:1,name:"三星笔记本",img:"https://m.360buyimg.com/babel/jfs/t1/117444/8/7913/170413/5ec683daEb1c3383c/2329ef2d22fa3a4f.jpg!q70.jpg",price:4590.0,num:1},
                             {id:2,name:"苹果手机",img:"https://m.360buyimg.com/babel/jfs/t1/98009/30/16479/84223/5e7cb5e6E314629e2/3dff9921d9b72d21.jpg!q70.jpg",price:6590.0,num:2}]
            }
        },
        methods:{
            handleChange(){
                console.log(this.productList);
                this.totalPrice();
            },
            totalPrice(){
                let total = 0;
                this.productList.forEach(p=>{
                    total += p.price * p.num;
                })
                console.log(total);
                this.total = total;
            }
        },
        created(){
            this.totalPrice();
        }
    }
</script>

<style scoped>

</style>


 技术分享图片

 

VUE + ElementUI VUE双向绑定实现购物车开发

原文:https://www.cnblogs.com/shanzhongqi/p/12986793.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!