博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
2020-11-21 Vue08-购物车案例 && filter,map,reduce
阅读量:3957 次
发布时间:2019-05-24

本文共 2081 字,大约阅读时间需要 6 分钟。

40-41过滤器-42-43

  
Document
出版名称 出版日期 价格 购买数量 操作
{ {item.id}} { {item.name}} { {item.date}} { {item.price | showPrice}} { {item.count}}

总价格:{
{totalPrice | showPrice}}

购物车为空

 

table{  border: 1px solid #e9e9e9;  border-collapse: collapse;  border-spacing: 0;}th, td{  padding: 8px 16px;  border: 1px solid #e9e9e9;  text-align: center;}th{  background-color: #f7f7f7;  color: #5c6b77;  font-weight: 600;}

 

const app = new Vue({  el: '#app',  data: {    books: [      {        id: 1,        name: '《算法导论1》',        data: '2006-9',        price: 85.00,        count: 1      },      {        id: 2,        name: '《算法导论2》',        data: '2006-9',        price: 85.00,        count: 1      },      {        id: 3,        name: '《算法导论3》',        data: '2006-9',        price: 85.00,        count: 1      },      {        id: 4,        name: '《算法导论4》',        data: '2006-9',        price: 85.00,        count: 1      },      {        id: 5,        name: '《算法导论5》',        data: '2006-9',        price: 85.00,        count: 1      },    ]  },  methods: {    // getFinalPrice(price){    //   return '¥' + price.toFixed(2);    // }    decrement(index){      this.books[index].count--;    },    increment(index){      this.books[index].count++;    },    removeHandle(index){      this.books.splice(index,1);    }  },  computed: {    totalPrice(){      let totalPrice = 0;      for(let i = 0; i < this.books.length; i++){        totalPrice += this.books[i].price * this.books[i].count;      }      return totalPrice;    }  },  filters: {     showPrice(price){      return '¥' + price.toFixed(2);     }  }})

 

 

 

知识点补充

 

    for(let i in arr)      i是数组的索引值;

    for(let i of arr)     i是数组的某一为的值;

 

 

 

 

 

转载地址:http://detzi.baihongyu.com/

你可能感兴趣的文章
ntfs分区iis故障的解决
查看>>
个人创业“六大死穴”
查看>>
最重要的 12个 J2EE 最佳实践
查看>>
通过Java Swing看透MVC设计模式
查看>>
Java 理论与实践: 关于异常的争论
查看>>
编写高效的线程安全类
查看>>
提高Java代码可重用性的三个措施
查看>>
编写跨平台Java程序注意事项
查看>>
富人和穷人的12个经典差异
查看>>
java 注意事项[教学]
查看>>
MetaWeblogAPI测试
查看>>
软件配置管理概念-1,介绍
查看>>
软件配置管理概念-2,用户角色
查看>>
软件配置管理概念-3,CM系统的概念
查看>>
JSP/Servlet应用程序优化八法
查看>>
人生必修的181条佛理
查看>>
The Most Widely Used Java Libraries
查看>>
简单在单机使用apache-james(开源邮件服务器)
查看>>
lsof 快速起步
查看>>
使用ScribeFire方便地发布blog
查看>>