1、效果

金额保留两位小数,并加上单位元

2、index.html

<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8"> <meta name="viewport"
content="width=device-width, user-scalable=no, initial-scale=1.0">
<title>Title</title>
<link rel="stylesheet" href="css/index.css">
</head>
<body>
<div id="app">
<!--<h2>{{title}}</h2>-->
<li v-for="(item,index) in productList"> <div>金额:{{item.productPrice*item.productQuentity | formatMoney}}</div> <!--注意元需要用双引号,不能用单引号,会出错-->
<div>金额:{{item.productPrice*item.productQuentity | money("元")}}</div> </li> </div>
<script src="js/lib/vue.min.js"></script>
<script src="js/lib/vue-resource.min.js"></script>
<script src="js/cart.js"></script>
</body>
</html>

3、cart.js

/**
* Created by kk on 2017/4/16.
*/
new Vue({
el:"#app",
data:{
// title:"hello vue"
totalMoney:0,
productList:[]
},
filters:{
formatMoney:function (value) {
return "¥"+value.toFixed(2)
}
},
mounted:function () {
//类似于jquery中的ready方法
this.$nextTick(function () {
this.cartView();
}) },
methods:{
cartView:function () {
// this.title="Vue hello"
//var _this=this;
// this.$http.get("data/cart.json",{"id":123}).then(function (res) {
// _this.productList=res.body.result. productList;
// _this.totalMoney=res.body.result.totalMoney;
// });
// 这里使用了ES6语法=>将this指向外部,不用再使用_this
        let _this=this;
this.$http.get("data/cart.json",{"id":123}).then(res=> {
this.productList=res.body.result. productList;
this.totalMoney=res.body.result.totalMoney;
});
}
} });
<!--注意Vue要大写v,不然会报错-->
Vue.filter("money",function (value,type) {
return "¥"+value.toFixed(2)+type;
});

最新文章

  1. Windbg Extension NetExt 使用指南 【1】 ---- NetExt 介绍
  2. 【记录】ASP.NET MVC AuthorizeAttribute OnAuthorization 验证跳转
  3. div里嵌套了img底部会有白块问题和图片一像素问题解决
  4. java JDK8 学习笔记——第16章 整合数据库
  5. 用PYTHON + PYWIN32 + WMI获取WINDOWS系统基本信息
  6. 从MVC到前后端分离
  7. Design Pattern ——Builder
  8. 使用Keil软件编写汇编源程序应注意事项
  9. haproxy反向代理
  10. [BZOJ1977][BeiJing2010组队]次小生成树
  11. python slots
  12. divide_3
  13. Android——对话框2(日期和时间对话框)
  14. Exchange 2016证书配置
  15. 【bzoj2318】game with probability
  16. COW写时复制
  17. 破解myBase试用到期
  18. PHP | Uploading and reading of files and database 【PHP | 文件的上传和读取与数据库】
  19. 杂项-Grunt:grunt build 打包和常见错误
  20. XCODE 4.5 IOS多语言设置 及NSLocalizedString和NSLocalizedStringFromTable的用法。

热门文章

  1. Java微信分享接口开发
  2. Android拦截外拨电话
  3. 清除li内a标签的float=left实现a标签在li内居中显示(ul内li不居中显示)
  4. 每日学习与工作计划移至日事清APP
  5. Python实现鸢尾花数据集分类问题——基于skearn的LogisticRegression
  6. MySQL 分区表原理及数据备份转移实战
  7. 魅族MX四核手机转让,二手淘宝上+hi-pda论坛结合使用成功已出
  8. 乙醇的webdriver实用指南java版本
  9. memcache 与 redis 为web app 带来的性能提升
  10. 你永远学不会的设计--&gt;百度地图map api key 的设置