vue中过滤器filters的使用

组件内写法

filters:{
    filter:function(data,arg1,arg2){
        return ....
    }
}

全局写法

filters('filter',function(data,arg1,arg2){
    retrun ....
})

1.在html中使用
{{ msg | filter('arg1','arg2') }}
// msg对应函数中的第一个参数data,arg1为第二个参数,类推
2.methods中使用,并传参
methods:{
    fn(){
        let filter = this.$options.filters['filter']
        let data = filter(this.msg,arg1,arg2) } }
3.在v-html中使用filters
<p v-html="$options.filters.filter(this.msg,arg1,arg2)"></p>
每一件与众不同的绝世好东西,其实都是以无比寂寞的勤奋为前提的,要么是血,要么是汗,要么是大把大把的曼妙青春好时光

组件内写法

filters:{
    filter:function(data,arg1,arg2){
        return ....
    }
}

全局写法

filters('filter',function(data,arg1,arg2){
    retrun ....
})

1.在html中使用
{{ msg | filter('arg1','arg2') }}
// msg对应函数中的第一个参数data,arg1为第二个参数,类推
2.methods中使用,并传参
methods:{
    fn(){
        let filter = this.$options.filters['filter']
        let data = filter(this.msg,arg1,arg2) } }
3.在v-html中使用filters
<p v-html="$options.filters.filter(this.msg,arg1,arg2)"></p>

猜你喜欢

转载自www.cnblogs.com/sexintercourse/p/10231122.html