Vue中全局过滤器的基本使用

请陛下批阅

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>过滤器的使用</title>
    <script src="../../vue/vue.js"></script>
</head>
<body>
<div id="app">
    <p>{{ msg | msgFormat }}</p>
</div>
</body>
<script>
    //定义一个 Vue 全局的过滤器 (创建vue实例之前定义全局过滤器)
    Vue.filter('msgFormat', function (msg) {
        return msg.replace(/爱/g, '喜欢过');
    });

    var vm = new Vue({
        el: '#app',
        data: {
            msg: '我曾经也爱过你,但是今后我即将离开.我即将为将来的那个她付出我全部的爱!!!!'
        }
    });
</script>
</html>
发布了62 篇原创文章 · 获赞 0 · 访问量 1247

猜你喜欢

转载自blog.csdn.net/weixin_45616246/article/details/105374450