<!DOCTYPE html> <html> <head> <meta charset="utf-8"> <title>Vue 示例</title> </head> <body> <div id="app" > 总价{{ prices }} </div> <script src="https://unpkg.com/vue/dist/vue.min.js"></script> <script> var padDate = function(value){ return value < 10 ? '0' + value :value; } var app = new Vue({ el: '#app', data: { package1: [{ name: 'iPhone 7', price: 7199, count:2 }, { name: 'iPad', price: 2888, count: 1 }], package2: [{ name: 'apple', price: 3, count:6 }, { name: 'orange', price: 4.98, count: 20 }] } , computed: { prices: function () { var prices = 0; for (let index = 0; index < this.package1.length; index++) { prices+= this.package1[index].price * this.package1[index].count; } for (let index = 0; index < this.package2.length; index++) { prices +=this.package2[index].price*this.package2[index].count; } return prices; } } }) </script> </body> </html>