<body>
<div id="app">
<h2>{{firstName+' '+lastName}}</h2>
<h2>{{getfullName()}}</h2>
<h2>{{fullName}}</h2>
<h2>总价格:{{totalPrice}}</h2>
</div>
<script src="js/vue.js">
</script>
<script>
const app = new Vue({
el: '#app',
data: {
firstName: 'cloud',
lastName: 'aireth',
books: [
{id: 10,name:'san1',price: 100},
{id: 11,name:'san1',price: 110},
{id: 12,name:'san1',price: 101},
{id: 13,name:'san1',price: 92}
]
},
//计算属性
computed: {
fullName(){
return this.firstName + ' ' + this.lastName;
},
totalPrice(){
let result = 0;
for(let book of this. books){
result += book.price;
}
return result;
}
},
methods:{
getfullName(){
return this.firstName + ' ' + this.lastName;
}
}
})
</script>
</body>