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


<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>


 

 


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM