//調用過濾器
//msg是返回數據的變量
//format是指定的過濾器,這個過濾器定義在Vue上
<p>{{ msg | format }}</p>
Vue.filter('format', function (data) {
return data.replace(new RegExp('x','gm'),'a');
});
<p>{{msg | format('hello') }}</p>
Vue.filter('format', function (data,arg) {
return data.replace(new RegExp('x', 'gm'), arg);
});
<p>{{msg | format | format2 | format3 }}</p>
<div id="app">
{{msg | filter1}}
</div>
var vueObj = new Vue({
el: "#app",
data: {
msg:"xxx"
},
filters: {
filter1: function (data) {
return data.replace(new RegExp("x", "gm"), "a");
}
}
});