demo738.html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>Document</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}}</td>
<td>
<button>-</button> {{item.count}}
<button>+</button>
</td>
<td>
<button>移除</button>
</td>
</tr>
</tbody>
</table>
</div>
<script src="./js/vue.js">
</script>
<script src="./js/main.js">
</script>
<script>
</script>
</body>
</html>
main.js
const app = new Vue({
el: '#app',
data: {
books: [{
id: 1,
name: '算法导论',
data: '2006-9',
price: 85.00,
count: 1
}, {
id: 2,
name: '算法导论',
data: '2006-9',
price: 85.00,
count: 1
}, {
id: 3,
name: '算法导论',
data: '2006-9',
price: 85.00,
count: 1
}, {
id: 4,
name: '算法导论',
data: '2006-9',
price: 85.00,
count: 1
}, ]
},
methods: {
},
filters: {
getFinal(price) {
return '$' + price.toFixed(2)
}
}
})
运行结果