-过滤器-自定义全局过滤器

<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>Document</title>
</head>

<body>

    <div id="app">

        <h1>{{acount | currency('€')}}</h1>

    </div>

    <script src="./vue.js"></script>
    <script>

        // 使用 Vue.filter() 方法自定义全局过滤器
        Vue.filter('currency', function (value, flag) {
            flag = flag || '¥';
            return flag + value.toFixed(2);
        })

        new Vue({
            el: '#app',
            data: {
                acount: 2000
            }
        })

    </script>
</body>

</html>
发布了151 篇原创文章 · 获赞 1 · 访问量 1851

猜你喜欢

转载自blog.csdn.net/qq_45802159/article/details/103835679