1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56
| const app = new Vue({ el: '#app', data: { books: [ { name: "《算法导论》", beginDate: "2006-9", price: 85.00, count: 1 }, { name: "《UNIX编程艺术》", beginDate: "2006-2", price: 59.00, count: 1 }, { name: "《编程大全》", beginDate: "2008-10", price: 39.00, count: 1 }, { name: "《代码大全》", beginDate: "2006-3", price: 128.00, count: 1 }, ] }, methods: { increment(index){ this.books[index].count++ }, decrement(index){ this.books[index].count-- }, remove(index){ this.books.splice(index,1) } }, computed: { totalPrice(){ return this.books.map(book => book.price*book.count) .reduce((preValue,currentValue) => preValue+currentValue) } }, filters: { showPrice: function(price){ console.log(typeof price); let priceStr = price.toFixed(2) console.log(priceStr); return "¥" + priceStr } } })
|