码迷,mamicode.com
首页 > 其他好文 > 详细

vue28-2.0-过滤器

时间:2017-06-11 18:18:51      阅读:178      评论:0      收藏:0      [点我收藏+]

标签:black   实现   charset   inpu   pre   json   智能   通过   todo   

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>智能社——http://www.zhinengshe.com</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>

        window.onload=function(){
            new Vue({
                el:#box,
                data:{
                    msg:123
                }
            });
        };
    </script>
</head>
<body>
    <div id="box">
        {{msg | currency}}    <!--没有效果-->
    </div>
</body>
</html>
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>智能社——http://www.zhinengshe.com</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>

        window.onload=function(){
            new Vue({
                el:#box,
                data:{
                    msg:{a:1,b:2,c:3}
                }
            });
        };
    </script>
</head>
<body>
    <div id="box">
        {{msg}}    <!--不需要{{msg | json}}:{a:1,b:2,c:3}-->
    </div>
</body>
</html>
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>智能社——http://www.zhinengshe.com</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>
        Vue.filter(toDou,function(n){
            //alert(input);
            return n<10?0+n:‘‘+n;
        });

        window.onload=function(){
            new Vue({
                el:#box,
                data:{
                    msg:9
                }
            });
        };
    </script>
</head>
<body>
    <div id="box">
        {{msg | toDou}}  <!--toDou()参数是msg-->
    </div>
</body>
</html>
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>智能社——http://www.zhinengshe.com</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>
        Vue.filter(toDou,function(n,a,b){
            alert(a+,+b);
            //alert(input);
            return n<10?0+n:‘‘+n;
        });

        window.onload=function(){
            new Vue({
                el:#box,
                data:{
                    msg:9
                }
            });
        };
    </script>
</head>
<body>
    <div id="box">
        {{msg | toDou ‘12‘ ‘5‘}}
    </div>
</body>
</html>
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>智能社——http://www.zhinengshe.com</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>
        Vue.filter(toDou,function(n,a,b){
            alert(a+,+b);
            //alert(input);
            return n<10?0+n:‘‘+n;
        });

        window.onload=function(){
            new Vue({
                el:#box,
                data:{
                    msg:9
                }
            });
        };
    </script>
</head>
<body>
    <div id="box">
        {{msg | toDou(‘12‘,‘5‘)}}
    </div>
</body>
</html>

 

6. 过滤器
    之前:
        系统就自带很多过滤
        {{msg | currency}}
        {{msg | json}}
        ....
        limitBy
        filterBy
        .....
    一些简单功能,自己通过js实现

    到了2.0, 内置过滤器,全部删除了

    lodash    工具库框架,    _.debounce(fn,200)

    自定义过滤器——还有
        但是,自定义过滤器传参

        之前:    {{msg | toDou ‘12‘ ‘5‘}}
        现在:     {{msg | toDou(‘12‘,‘5‘)}}

 

vue28-2.0-过滤器

标签:black   实现   charset   inpu   pre   json   智能   通过   todo   

原文地址:http://www.cnblogs.com/yaowen/p/6985759.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!