<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title></title>
</head>
<body>
<div id="app">
<h2>总价格:{{totalprice}}</h2>
</div>
<script src='../js/vue.js'></script>
<script>
const app = new Vue({
el:'#app',
data:{
books:[
{id:1,name:'数据结构',price:22},
{id:2,name:'操作系统',price:23},
{id:3,name:'计算机组成原理',price:20},
{id:4,name:'计算机网络',price:28}
]
},
computed:{
totalprice:function(){
let result = 0;
for(let i=0;i<this.books.length;i++){
result += this.books[i].price
}
return result
}
}
})
</script>
</body>
</html>