<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>实操题</title>
</head>
<body>
    <div id="app">
        <h3>商品列表</h3>
        {{array}}
        <ul>
            <li v-for="a in array">
                名称:{{a.name}}--价格:{{a.price}}--数量:{{a.count}}
                <input type="number" v-model="a.count" v-on:change="totalPrice()">
            </li>
        </ul>
        <p>methods总价:{{total}}</p>
    </div>

    <script src="../js/vue.js"></script>

    <script>
        let myArray = [
            {
                name:'手机',
                price:3999,
                count:0,
            },
            {
                name:'电视',
                price:8999,
                count:0,
            },
            {
                name:'洗衣机',
                price:1999,
                count:0,
            },
        ];

        let vm = new Vue({
            el:'#app',
            data:{
                array:myArray,
                total:0
            },
            methods:{
                totalPrice:function () {
                    let sum = 0;
                    for(i=0;i<this.array.length;i++){
                        sum += this.array[i].price * this.array[i].count;
                    }
                    this.total = sum;
                }
            }
        });
    </script>
</body>
</html>