zoukankan      html  css  js  c++  java
  • vue-filters(过滤器)

      局部过滤器:

    <html>
    
    <head>
        <title>vue</title>
        <meta charset="utf-8">
    </head>
    
    <body>
        <div id="app">
            {{msg | toFixed(1)}}
            <!-- msg是参数input的值,方法里的参数都是作为input后的参数 -->
        </div>
    </body>
    <script src="node_modulesvuedistvue.js"></script>
    <script>
        let vm = new Vue({
            el: "#app",
            filters: {
                // toFixed(input,param1,param2,param3)
                toFixed(input, num) { //第二个参数为小数点个数
                    return '' + input.toFixed(num);
                }
            },
            data:{
                msg:15.123
            }
        });
    </script>
    
    </html>

      全局过滤器(记得放在所有实例之前)

    <html>
    
    <head>
        <title>vue</title>
        <meta charset="utf-8">
    </head>
    
    <body>
        <div id="app">
            {{msg | my(2)}}
            <!-- msg是参数input的值,方法里的参数都是作为input后的参数 -->
        </div>
    </body>
    <script src="node_modulesvuedistvue.js"></script>
    <script>
        // 全局过滤
        // Vue.filter(name,function)
        Vue.filter('my',(input,num)=>{
            return '' + input.toFixed(num);
        })
        // 局部过滤
        let vm = new Vue({
            el: "#app",
            filters: {
                // toFixed(input,param1,param2,param3)
                toFixed(input, num) { //第二个参数为小数点个数
                    return '' + input.toFixed(num);
                }
            },
            data:{
                msg:15.123
            }
        });
    </script>
    
    </html>

  • 相关阅读:
    栈和队列
    数组的遍历查找
    字符串的子串
    两个字符串
    字符串的遍历
    字符串的替换
    数组和矩阵
    Django 自带的ORM增删改查
    what's the CRSF ??
    Rabbitmq -Publish_Subscribe模式- python编码实现
  • 原文地址:https://www.cnblogs.com/angle-xiu/p/11410800.html
Copyright © 2011-2022 走看看