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

Vue过滤器 filters

时间:2020-05-29 09:40:41      阅读:60      评论:0      收藏:0      [点我收藏+]

标签:ice   lan   NPU   v-model   mode   var   div   utf-8   https   

局部过滤器:

<!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>

 

Vue过滤器 filters

标签:ice   lan   NPU   v-model   mode   var   div   utf-8   https   

原文地址:https://www.cnblogs.com/antao/p/12985464.html

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