Vue中的filter过滤器

基础用法

    <div id="app">
        {{x | tese}}
    </div>
复制代码
const app = new Vue({
    el: '#app',
    data: {
        x:1
    },
    filters:{
        tese(value){
            return value == 0?'男':'女'
        }
    },
    conponents: {},
    methods: {},
    mounted() {}
})
复制代码

传值法

<div id="app">
    {{x | tese('人')}}
</div>
复制代码
const app = new Vue({
    el: '#app',
    data: {
        x:1
    },
    filters:{
        tese(value,params){
            return (value == 0?'男':'女') + params
        }
    },
    conponents: {},
    methods: {},
    mounted() {}
})
复制代码

还可以多次过滤

<div id="app">
    {{x | tese('人') | test2}}
</div>
复制代码
© 版权声明
THE END
喜欢就支持一下吧
点赞0 分享