根据coderwhy002老师的视频整理
<body > <div id="app"> 总价 {{totalPrice}} </div> </body> <script> const app = new Vue({ el:‘#app‘, data:{ books:[ {id:1,name:‘Unix编程艺术‘,price:99}, {id:2,name:‘代码大全‘,price:100}, {id:3,name:‘深入理解计算机原理‘,price:101}, {id:4,name:‘现代操作系统‘,price:100}, ] }, computed:{ totalPrice:function(){ let result =0 for(let i=0;i<this.books.length;i++){ result += this.books[i].price } return result } } }) </script>
原文:https://www.cnblogs.com/polax/p/12852651.html