私有过滤器的优先级高于全局过滤器。
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title></title>
</head>
<body>
<div id="app">
<p>{{msg | msgFilter1 }}</p>
</div>
<script type="text/javascript" src="./lib/vue-2.6.10.js"></script>
<script>
Vue.filter('msgFilter',function(msg, arg, arg1){
//return msg.replace('单纯', '可爱');
return msg.replace(/单纯/g, arg + arg1);
});
Vue.filter('msgFilter1',function(msg){
//return msg + '===add===';
return msg.replace(/单纯/g, 'xxx');
});
var vm = new Vue({
el: '#app',
data: {
msg: '我很单纯,一直单纯,是真的非常单纯'
},
methods: {
},
filters: {
msgFilter1 : function(msg){
return msg.replace(/单纯/g, 'sss');
}
}
})
</script>
</body>
</html>
网友评论