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;
});

vue中的filters的用法的更多相关文章

  1. 详解Vue中watch的高级用法

    我们通过实例代码给大家分享了Vue中watch的高级用法,对此知识点有需要的朋友可以跟着学习下. 假设有如下代码: <div> <p>FullName: {{fullName} ...

  2. vue 中 命名视图的用法

    今天主要记录  vue中命名视图的用法 先奉上官网网址:https://router.vuejs.org/zh/guide/essentials/named-views.html 一般情况下,一个页面 ...

  3. vue中watch的详细用法

    在vue中,使用watch来响应数据的变化.watch的用法大致有三种.下面代码是watch的一种简单的用法: <input type="text" v-model=&quo ...

  4. vue中watch的详细用法(转载)

    在vue中,使用watch来响应数据的变化.watch的用法大致有三种.下面代码是watch的一种简单的用法: <input type="text" v-model=&quo ...

  5. vue中this.$set的用法

    之前了解这个方法的时候,感觉这一辈子也用不到这个方法,因为当时没有应用场景,但是还真有用的时候,我相信你们也有用到时候. 从三个方面给大家说一下这个this.$set: 1.this.$set实现什么 ...

  6. vue中过滤器filters的使用

    组件内写法 filters:{ filter:function(data,arg1,arg2){ return .... } } 全局写法 filters('filter',function(data ...

  7. vue中$ref的基本用法

    1.使用在一般的标签上 <div id="app"> <input ref="count" type="text" v-m ...

  8. vue中watch函数的用法

    vue中watch函数: 不仅可以判断路由变化(上篇博客有介绍),还可以判断数据的变化 (1):首先写watch函数 (2):在data里定义值 (3):在methods里写方法 (4):使用值

  9. vue中router-link的详细用法

    官网文档地址:https://router.vuejs.org/zh/api/#to 今天项目突然有需求,让vue中的一个页面跳转到另一个页面 // 字符串 <router-link to=&q ...

随机推荐

  1. Ubuntu字库安装

    目录 [隐藏] 1 字体相关库的简介 1.1 LibXft 1.2 Cairo 1.3 Fontconfig 1.4 Freetype 1.5 Pango 2 基本概念 2.1 点阵字体与矢量字体 2 ...

  2. iOS presentedViewController和presentingViewController的区别

    当我们用present进行界面跳转时,会涉及到一个传向关系. 比如:A -> B    界面A跳转界面B A.presentedViewControlle = B B.presentingVie ...

  3. CSRF攻击与防御(写得非常好)

    转自:http://blog.csdn.net/stpeace/article/details/53512283 CSRF概念:CSRF跨站点请求伪造(Cross—Site Request Forge ...

  4. 【转】GDB中应该知道的几个调试方法

    文章来源:http://coolshell.cn/articles/3643.html GDB中应该知道的几个调试方法 2011年02月10日 陈皓 评论 40 条评论  70,776 人阅读 七.八 ...

  5. Linux主要shell命令详解(下)

    命令行编辑操作 功能 Ctrl+b或左箭头键 左移一个字符(移至前一个字符) Ctrl+f或右箭头键 右移一个字符(移至后一个字符) Ctrl+a 移至行首 Ctrl+e 移至行尾 Esc b 左移一 ...

  6. 合格linux运维人员必会的30道shell编程面试题及讲解

    原创作品,允许转载,转载时请务必以超链接形式标明文章 原始出处 .作者信息和本声明.否则将追究法律责任.http://oldboy.blog.51cto.com/2561410/1632876 超深度 ...

  7. Fedora 20 安装搜狗拼音输入法

    1.卸载ibus sudo yum remove ibus    gsettings set org.gnome.settings-daemon.plugins.keyboard active fal ...

  8. MFC坐标转换

    1.GetWindowRect是取得窗口在屏幕坐标系下的RECT坐标(包括客户区和非客户区),这样可以得到窗口的大小和相对屏幕左上角(0,0)的位置. 2.GetClientRect取得窗口客户区(不 ...

  9. SpringBoot配置属性之NOSQL

    SpringBoot配置属性系列 SpringBoot配置属性之MVC SpringBoot配置属性之Server SpringBoot配置属性之DataSource SpringBoot配置属性之N ...

  10. MySQL慢查询mysqlsla

    转:http://www.osyunwei.com/archives/7659.html 必须在MySQL服务器上安装mysqlsla 1.mysqlsla是perl编写的脚本,运行mysqlsla需 ...