您现在的位置:首页 >> 前端 >> 内容

vue.js中filters的用法详解

时间:2018/3/29 17:12:36 点击:

  核心提示:html部分p id=app{{message | filters2| filters3(true,priceCount)}}/pjs部分script type=text/var app = new ...

html部分

<p id="app">
      {{message | filters2| filters3(true,priceCount)}}
</p>

js部分

<script type="text/javascript">
    var app = new Vue({
          el: "#app",
          data: {
            message: 199,
            priceCount:.8
          },
          filters:{
            filters2:function (arg) {
              console.log("arg:"+arg)
              if(arg>100){
                return arg-8;
              }else {
                return arg;
              }
            },
            filters3:function (arg_1,arg_2,arg_3) {
              var result;
              console.log("arg_1:"+arg_1)
              console.log("arg_2:"+arg_2)
              console.log("arg_3:"+arg_3)
              if(arg_2){
                result = arg_1*arg_3;
                console.log("result"+result);
                return result;
              }else{
                result =arg_1;
                console.log("result"+result);
                return result
              }

            }
          }
        });
</script>
<script type="text/javascript">
    var app = new Vue({
          el: "#app",
          data: {
            message: 199,
            priceCount:.8
          },
          filters:{
            filters2:function (arg) {
              console.log("arg:"+arg)
              if(arg>100){
                return arg-8;
              }else {
                return arg;
              }
            },
            filters3:function (arg_1,arg_2,arg_3) {
              var result;
              console.log("arg_1:"+arg_1)
              console.log("arg_2:"+arg_2)
              console.log("arg_3:"+arg_3)
              if(arg_2){
                result = arg_1*arg_3;
                console.log("result"+result);
                return result;
              }else{
                result =arg_1;
                console.log("result"+result);
                return result
              }

            }
          }
        });
</script>

调试的结果:

vue.js中filters的用法详解

Tags:VU UE EJ JS 
作者:网络 来源:sweet_note