vue filters过滤器
vue filters过滤器
vue.js允许我们自定义过滤器,可被使用于一些常见的文本格式化,过滤器可以用在两个地方,双花括号插值和 v-bind表达式。最常见的就是双花括号插值。
比如如下代码:
{{message | filters2 | filters3(true, priceCount)}}
过滤器函数filters2接收到的第一个参数就是message的值,message的值将作为参数传入到filter2函数中,然后继续调用同样被定义为接收单个参数的
过滤器函数,因此filter3的第一个参数也是message的值,第二个参数是true,第三个参数是 priceCount.
代码如下:
<!DOCTYPE html>
<html>
<head>
<title>演示Vue</title>
<style> </style>
</head>
<body>
<div id="app">
{{message | filters2 | filters3(true, priceCount)}}
</div>
</body>
<script src="./vue.js"></script>
<script>
var app = new Vue({
el: '#app',
data: {
message: 100,
priceCount: .8
},
filters: {
filters2: function(arg) {
console.log("arg: " +arg);
if (arg > 90) {
return arg - 8;
} else {
return arg;
}
},
filters3: function(arg1, arg2, arg3) {
var res;
console.log("arg1: "+arg1);
console.log("arg2: "+arg2);
console.log("arg3: "+arg3);
if (arg2) {
res = (arg1 * 10 * arg3) / 10;
console.log("result"+res);
return res;
} else {
res = arg1;
console.log("result"+res);
return res;
}
}
}
})
</script>
</html>
vue filters过滤器的更多相关文章
- Vue -- filters 过滤器、倒计时效果
局部过滤器 时间.***号 <div id="wrapper" class="wrapper" style="display: none;&qu ...
- vue filters过滤器的使用
说的很详细 https://www.w3cplus.com/vue/how-to-create-filters-in-vuejs.html
- 六、vue基础--过滤器定义
七.过滤器定义 1.使用:{{username|strip}}.<a :href="url|strip">百度</a> 2.定义:都是定义一个函数,这个函数 ...
- Vue.js Cookbook: 添加实例属性; 👍 axios(4万➕✨)访问API; filters过滤器;
add instance properties //加上$,防止和已经定义的data,method, computed的名字重复,导致被覆写.//可以自定义添加其他符号. Vue.prototype. ...
- Vue学习之--------Vue中过滤器(filters)的使用(代码实现)(2022/7/18)
1.过滤器 1.1 概念 过滤器: 定义:对要显示的数据进行特定格式化后再显示(适用于一些简单逻辑的处理). 语法: 1.注册过滤器:Vue.filter(name,callback) 或 new V ...
- Vue自定义过滤器
gitHub地址: https://github.com/lily1010/vue_learn/tree/master/lesson05 一 自定义过滤器(注册在Vue全局) 注意事项: (1)全局方 ...
- vue filter过滤器简单应用
vue中过滤器,用于一些常见的文本格式化,用 | 来操作. 过滤器可以用在两个地方: 1.在{{}}双花括号中插入值 2.v-bind表达式中使用 <!-- 在双花括号中 --> {{ m ...
- vue的过滤器
Vue.Js 提供了强大的过滤器API,能够对数据进行各种过滤处理,返回需要的结果 vue的过滤器一般在JavaScript 表达式的尾部,由“|”符号指示: 过滤器可以让我们的代码更加优美,一般可以 ...
- vue自定义过滤器的创建和使用
1.简单介绍 过滤器的作用:实现数据的筛选.过滤.格式化. 过滤器的本质是一个有参数,有返回值的方法. 过滤器可以用在两个地方:双花括号插值和v-bind表达式(后者从2.1.0+开始支持 ...
随机推荐
- swift 基础小结02 -- VFL约束、属性的get和set方法、懒加载、方法替换
一.属性的get和set方法 1.自定义属性的set和get方法 private(set) var _image:UIImage? //自定义属性get,s ...
- Matlab function lorenzgui
function lorenzgui %LORENZGUI Plot the orbit around the Lorenz chaotic attractor. % This function an ...
- CDN使用心得:加速双刃剑
文章图片存储在GitHub,网速不佳的朋友,请看<CDN 使用心得:加速双刃剑> 或者 来我的技术小站 godbmw.com 本文以腾讯云平台的 CDN 服务为例,记录下在个人网站开发和公 ...
- Java集合之Vector源码分析
概述 Vector与ArrayLIst类似, 内部同样维护一个数组, Vector是线程安全的. 方法与ArrayList大体一致, 只是加上 synchronized 关键字, 保证线程安全, 下面 ...
- 自定义SharePoint2013 master page
SharePoint uses templates to define and render the pages that a site displays. The structure of a Sh ...
- python爬虫简单代码爬取郭德纲单口相声
搜索老郭的单口相声,打开检查模式,刷新 没有什么有价值的东东, 不过....清掉内容, 点击一个相声,再看看有些什么 是不是发现了些什么 我们来点击这个看看, 首先看一下headers, 这个url是 ...
- linux学习笔记-conky配置开机启动方法
我的邮箱地址:zytrenren@163.com欢迎大家交流学习纠错! 一.常用桌面的配置方法 创建启动文件并加入以下配置 ~/.config/autostart/conky.desktop [Des ...
- BUGList
Django : a. MySQL数据表还未创建时,不可在视图内直接使用模型类对象,产生报错 django.db.utils.ProgrammingError: (1146, "Table ...
- SuperMap iObject .NET开发完成后私有部署,打包安装
转载自:http://blog.csdn.net/supermapsupport/article/details/53319800 作者:皇皇 SuperMap iObjict .NET组件开发结束后 ...
- String全面解析
前言 public class Test { public static void main(String[] args) { String a = "abc"; String b ...