vue中的filters的用法
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的用法的更多相关文章
- 详解Vue中watch的高级用法
我们通过实例代码给大家分享了Vue中watch的高级用法,对此知识点有需要的朋友可以跟着学习下. 假设有如下代码: <div> <p>FullName: {{fullName} ...
- vue 中 命名视图的用法
今天主要记录 vue中命名视图的用法 先奉上官网网址:https://router.vuejs.org/zh/guide/essentials/named-views.html 一般情况下,一个页面 ...
- vue中watch的详细用法
在vue中,使用watch来响应数据的变化.watch的用法大致有三种.下面代码是watch的一种简单的用法: <input type="text" v-model=&quo ...
- vue中watch的详细用法(转载)
在vue中,使用watch来响应数据的变化.watch的用法大致有三种.下面代码是watch的一种简单的用法: <input type="text" v-model=&quo ...
- vue中this.$set的用法
之前了解这个方法的时候,感觉这一辈子也用不到这个方法,因为当时没有应用场景,但是还真有用的时候,我相信你们也有用到时候. 从三个方面给大家说一下这个this.$set: 1.this.$set实现什么 ...
- vue中过滤器filters的使用
组件内写法 filters:{ filter:function(data,arg1,arg2){ return .... } } 全局写法 filters('filter',function(data ...
- vue中$ref的基本用法
1.使用在一般的标签上 <div id="app"> <input ref="count" type="text" v-m ...
- vue中watch函数的用法
vue中watch函数: 不仅可以判断路由变化(上篇博客有介绍),还可以判断数据的变化 (1):首先写watch函数 (2):在data里定义值 (3):在methods里写方法 (4):使用值
- vue中router-link的详细用法
官网文档地址:https://router.vuejs.org/zh/api/#to 今天项目突然有需求,让vue中的一个页面跳转到另一个页面 // 字符串 <router-link to=&q ...
随机推荐
- usr/bin/X11各个程序中文详解
X11程序 animate 输出图形结果 bitmap bmtoa bounce 输出X屏幕保存结果 display 浏览编辑image magick图像 editres 编辑X11资源 flsfon ...
- java struts2入门学习实例--使用struts2快速实现多个文件上传
一.错误提示信息配置 昨天说到更改默认错误配置信息,我测试很多遍,一直都不对.下面贴出来,待以后有好方法了再补充吧. 首先新建一个properties文件,这里命名为testupload.proper ...
- HDU 3062 Party ( 2-sat tarjan)
Party Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total Submi ...
- SpringBoot项目eclipse运行正常maven install打包启动后报错ClassNotFoundException
parent的pom.xml <groupId>cn.licoy</groupId> <artifactId>parent</artifactId> & ...
- 【jsp】配置错误页面
1,使用JSP方式 如果配置是Jsp时,需要把isErrorPage设置为true, 以及设置 <%@ page language="Java" contentType=&q ...
- windows Maven3.0 服务器配置搭建
搭建nexus私服,原因很简单,不必多说,本文重点说下最新版的Maven 3.0.x系列的安装步骤. 最新版的网上中文资料很少,参考后都没成功.最后在官网的英文资料中得到答案,成功搞定. 1.确定我们 ...
- OpenCV 学习笔记 01 安装OpenCV及相关依赖库
本次学习是基于Window10进行的.语言为python3. 1 与opencv相关的库简介 1.1 numpy numpy 是 OpenCV 绑定 python 时所依赖的库,此意味着numpy在安 ...
- ios开发中用过的一些外部库总结 cocoapods list
下面几个库是在之前的一个ios app开发中使用过的一些外部库: 1. zbar :2. shakebox :3. processbar :4. tableviewcontroller :新版的sta ...
- the most beautiful media player on the linux platform.
the most beautiful media player on the linux platform------> deepin media player http://wiki.linu ...
- stm8 时钟输出引脚
CLK_CCO引脚是STM8的时钟输出引脚,若设置该脚输出主时钟Fmaster,时钟输出寄存器可以进行如下操作 CLK->CCOR=0X19;