Vue之自定义过滤器
来源:互联网 发布:放置江湖人物评价算法 编辑:程序博客网 时间:2024/06/07 07:25
使用Vue.filter('过滤器名称',方法);
1.
<!DOCTYPE html><html lang="en"><head> <meta charset="UTF-8"> <title></title> <meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=0"> <meta name="apple-mobile-web-app-capable" content="yes"> <meta name="apple-mobile-web-app-status-bar-style" content="black"> <style> </style> <script src="vue.js"></script> <script> </script></head><body> <div id="box"> {{a | toDou}} </div> <script> Vue.filter('toDou',function(input){ return input<10?'0'+input:''+input; }); var vm=new Vue({ data:{ a:9 }, methods:{ } }).$mount('#box'); </script></body></html>
效果:
2.带参数的自定义过滤器
<!DOCTYPE html><html lang="en"><head> <meta charset="UTF-8"> <title></title> <meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=0"> <meta name="apple-mobile-web-app-capable" content="yes"> <meta name="apple-mobile-web-app-status-bar-style" content="black"> <style> </style> <script src="vue.js"></script> <script> </script></head><body> <div id="box"> {{a | toDou 1 2}} </div> <script> Vue.filter('toDou',function(input,a,b){ alert(a+','+b); return input<10?'0'+input:''+input; }); var vm=new Vue({ data:{ a:9 }, methods:{ } }).$mount('#box'); </script></body></html>
3.自定义日期
<!DOCTYPE html><html lang="en"><head> <meta charset="UTF-8"> <title></title> <meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=0"> <meta name="apple-mobile-web-app-capable" content="yes"> <meta name="apple-mobile-web-app-status-bar-style" content="black"> <style> </style> <script src="vue.js"></script> <script> </script></head><body> <div id="box"> {{a | date}} </div> <script> Vue.filter('date',function(input){ var oDate=new Date(input); return oDate.getFullYear()+'-'+(oDate.getMonth()+1)+'-'+oDate.getDate()+' '+oDate.getHours()+':'+oDate.getMinutes()+':'+oDate.getSeconds(); }); var vm=new Vue({ data:{ a:Date.now() }, methods:{ } }).$mount('#box'); </script></body></html>
阅读全文
0 0
- Vue之自定义过滤器
- Vue过滤器和自定义过滤器
- Vue自定义过滤器
- Vue自定义过滤器
- Vue---自定义过滤器
- Vue自定义过滤器
- vue自定义过滤器
- vue 2.0 自定义过滤器
- Vue之过滤器
- vue之过滤器
- vue.js2.0自定义过滤器
- VUE自定义过滤器(注册在Vue全局)
- vue组件化挖矿之旅(三):vue-cli 自定义过滤器的使用
- vue.js之filter过滤器
- vue--购物车+计算价格+自定义过滤器
- vue 过滤器和自定义指令、组件
- Vue.js学习 Item14 – 过滤器与自定义过滤器
- vue之自定义指令
- 【一起来学C语言】常用进制的转换与应用(下)
- 遗传算法基础知识介绍
- 基于ViewDragHelper实现侧滑
- 练习week2 'caculator'
- 磁盘及分区
- Vue之自定义过滤器
- IDEA创建JavaWeb项目
- Hive中join的三种方式
- 欢迎使用CSDN-markdown编辑器
- 【分布式5】Zookeeper使用--命令行
- 转自其它博主的 关于优先级反转问题的解决方案
- 乔布斯斯坦福大学演讲英文原文
- 微信小程序画折线图
- 进化后的const分析