Vue过滤器
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Title</title>
</head>
<body>
<div id="app">
<table>
<thead>
<tr>
<th></th>
<th>出版名称</th>
<th>出版日期</th>
<th>价格</th>
<th>购买数量</th>
<th>操作</th>
</tr>
</thead>
<tbody>
<tr v-for="item in books">
<td>{{item.id}}</td>
<td>{{item.name}}</td>
<td>{{item.data}}</td>
<td>{{item.price|showPrice}}</td>
</tr>
</tbody>
</table>
</div>
<script type="text/javascript" src="../js/vue.js"></script>
<script>
const app = new Vue ({
el: '#app',
data: {
books:[
{id:1,name:'《算法争论》',data:'2006-9',price:85.00,count:1},
{id:1,name:'《unix编程艺术》',data:'2003-1',price:95.00,count:1},
{id:1,name:'《算法争论》',data:'2006-9',price:102.00,count:1},
{id:1,name:'《代码大全》',data:'2005-5',price:65.00,count:1}
],
},
filters:{
showPrice(price){
return '$' + price.toFixed(2)
}
}
})
</script>
</body>
</html>