• Vue过滤器 filters


    局部过滤器:

    <!DOCTYPE html>
    <html lang="en">
        <head>
            <meta charset="utf-8">
            <meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=0">
            <title>filters</title>
            <script src="https://cdn.jsdelivr.net/npm/vue/dist/vue.js" type="text/javascript" charset="utf-8"></script>
        </head>
        <body>
            <div id="app">
                <input type="text" v-model="test" placeholder="请输入"/>
                <div>{{test|filter1|filter2}}</div>
            </div>
        </body>
    </html>
    <script type="text/javascript" charset="utf-8">
        var app = new Vue({
            el: "#app",
            data: {
                test: ''
            },
            filters: {
                filter1: function(val) {
                    return val.toUpperCase();
                },
                filter2: function(val) {
                    var reg = /d/g;
                    return val.replace(reg, '*');
                }
            }
        });
    </script>

    全局过滤器:

    <!DOCTYPE html>
    <html lang="en">
        <head>
            <meta charset="utf-8">
            <meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=0">
            <title>filters</title>
            <script src="https://cdn.jsdelivr.net/npm/vue/dist/vue.js" type="text/javascript" charset="utf-8"></script>
        </head>
        <body>
            <div id="app">
                <input type="text" v-model="test" placeholder="请输入" />
                <div>{{test|filter1|filter2}}</div>
            </div>
        </body>
    </html>
    <script type="text/javascript" charset="utf-8">
        Vue.filter('filter1', function(val) {
            return val.toUpperCase();
        });
        
        Vue.filter('filter2', function(val) {
            var reg = /d/g;
            return val.replace(reg, '*');
        });
        
        var app = new Vue({
            el: "#app",
            data: {
                test: ''
            },
        });
    </script>
    一辈子很短,努力的做好两件事就好;第一件事是热爱生活,好好的去爱身边的人;第二件事是努力学习,在工作中取得不一样的成绩,实现自己的价值,而不是仅仅为了赚钱。
  • 相关阅读:
    [转]理解java的三大特性之多态
    [转]java:IO流学习小结
    Base64 加密之中文乱码
    piwik优化之定时任务生成统计数据
    php统计中英文混合的文章字数
    Linux常用命令之定时任务
    skype在线状态代码详解
    php+google/baidu翻译接口
    php限制文件下载速度的代码
    PHP破解wifi密码(wifi万能钥匙的接口)
  • 原文地址:https://www.cnblogs.com/antao/p/12985464.html
Copyright © 2020-2023  润新知