1 <html lang="en">
 2 
 3 <head>
 4     <meta charset="UTF-8">
 5     <meta name="viewport" content="width=device-width, initial-scale=1.0">
 6     <meta http-equiv="X-UA-Compatible" content="ie=edge">
 7     <title>过滤器的使用</title>
 8     <script src="../js/vue.js"></script>
 9 </head>
10 
11 <body>
12     <div id="app">
13         <p>{{msg | newFormat}}</p>
14 
15     </div>
16     <script>
17         Vue.filter('newFormat',function(msg){
18             //replace除了方法第一个能字符串之外,也可以写正则
19             return msg.replace(//g,'酷酷')
20 
21         })
22         var vm = new Vue({
23             el: '#app',
24             data: {
25                 msg: '我是小男孩,可爱的小男孩,小的让人怜爱的感觉,小的让人不发脾气'
26             }
27         })
28     </script>
29 </body>
30 
31 </html>