订单界面
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Title</title>
<link rel="stylesheet" href="cs.css">
</head>
<body>
<div id="app">
<div v-if="books.length ">
<table>
<thead>
<tr>
<th>书籍名称</th>
<th>出版日期</th>
<th>购买数量</th>
<th>价格</th>
</tr>
</thead>
<tbody>
<tr v-for ="(item,index) in books">
<td>{{item.id}}</td>
<td>{{item.name}}</td>
<td>{{item.data}}</td>
<td>{{item.price | finalprice}}</td><!--过滤器的使用 <td>{{item.price | finalprice}}</td>过滤器的使用 -->
-->
<td>
<button @click="decrese(index)" >-</button>
{{item.count}}
<button @click="increse(index)" >+</button>
</td>
<td> <button @click="increse2(index)">移除</button></td>
</tr>
</tbody>
</table>
<h2>{{totalPrice | finalprice}}</h2>
</div>
<h2 v-else>购物车为空</h2>
</div>
<script src="../sjms/hellojs/js/vue.js"></script>
<script src="jjs.js"></script>
</body>
</html>
const app =new Vue({
el:'#app',
data:{
books:[
{
id:1,
name:'aa',
data:'2020-6',
price:30,
count:1
},
{
id:2,
name:'bb',
data:'2020-6',
price:90,
count:1
}
]
},
computed:{
totalPrice(){
let totalPrice = 0;
debugger
for(let i =0 ;i<this.books.length;i++){
totalPrice += this.books[i].price * this.books[i].count
}
return totalPrice;
}
},
filters:{
finalprice(price){
return '$'+ price.toFixed(2);
}
},
methods:{
decrese(index){
this.books[index].count--;
},
increse(index){
this.books[index].count++;
},
increse2(index){
this.books.splice(index,1);
},
}
})