<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <script src="https://cdn.jsdelivr.net/npm/vue"></script> <title>Vue过滤器</title> </head> <body> <div id="app"> <p>{{user|strip}}</p> 传递参数 <p>{{user|strip2(‘*‘)}}</p> 过滤器串联 <p>{{user|strip|hello}}</p> </div> <script> // 全局变量 Vue.filter("strip", function (value) { return value.replace(" ", "") }) Vue.filter("strip2",function(value,string){ return value.replace(" ",string) }) Vue.filter("hello",function(value){ return "hello" + value }) new Vue({ el: "#app", data: { user: "X san" }, }) </script> </body> </html>
原文:https://www.cnblogs.com/xshan/p/12356013.html