Vue-过滤器

过滤器

可以用作一些常见的文本格式化,比如日期,钱等。

分类

  • 全局过滤器
  • 私有过滤器

Vue.filter

<div id="app">
    <h1>{{price|currency}}</h1>
</div>
/*过滤器*/
Vue.filter("currency",function (val) {
        val=val||0;
        return "¥"+val;
});

var app = new Vue({
        el: '#app',
        data: {
                price:10
        }

})

过滤器传递参数

<div id="app">
    <h1>{{price|currency('元')}}</h1>
</div>

Vue.filter("currency",function (val,end) {
        val=val||0;
        return "¥"+val+end;
});


  转载请注明: linis Vue-过滤器

 上一篇
Vue-插槽 Vue-插槽
插槽slot-实现内容分发 实名插槽 匿名插槽 匿名插槽 <slot> 标签 <div id="app"> <show> <p>I'm
2019-05-07
下一篇 
Vue-组件 Vue-组件
组件 全局组件 Vue.component <div id="app"> <tao></tao> </div> //创建构造器 var Alert = Vue.extend( { temp
2019-05-05
  目录