search

Home  >  Q&A  >  body text

Is there a way in vuejs like angularjs filter

vuejs noob
Now let’s practice using vuejs on the projects we have done with angularjs. I can use filters in angualrjs like this
<p class="borderClass infomation-item" ng-repeat=" items in newlist|filterByObj:'4'" ng-if="$index!=0">

            <a ui-sref="tv_pro({id:items.programesHistory_id})">
                <span ng-bind="items.programesHistory_name"></span>
                <p class="cache">{{items.programesHistory_description}}</p>
            </a>
        </p>
        
      filterByObj写在js里面然后接收item的值和过滤参数  
      
      在vuejs中貌似只能不能传递参数,在v-for中如果写过虑器
高洛峰高洛峰2835 days ago625

reply all(5)I'll reply

  • 迷茫

    迷茫2017-05-19 10:31:06

    Reference stamp

    reply
    0
  • 伊谢尔伦

    伊谢尔伦2017-05-19 10:31:06

    https://cn.vuejs.org/v2/api/#...

    reply
    0
  • 淡淡烟草味

    淡淡烟草味2017-05-19 10:31:06

    There is a filter in vue that can achieve what you want
    https://vuefe.cn/v2/api/#filters
    Like this:

    // template里面
    <p>{{averageMonthPay|fMoney}}</p>
    // script里面
    name: 'confirm',
    filters: {
        fMoney(num = 0) {
            return (num / 1000).toFixed(2)
        }
    },
    props: {},
    data() {}

    reply
    0
  • 迷茫

    迷茫2017-05-19 10:31:06

    Either write it as a filter, or use calculated properties, see which one suits you. There are instructions in the vue.js documentation.

    reply
    0
  • 習慣沉默

    習慣沉默2017-05-19 10:31:06

    Because filter is a JavaScript function, you can do this:

    <template>
    <p class="borderClass infomation-item"v-for="(items, index) in newlist" v-if="index !== 0">
    {{items | filterByObj(4) }}
    </p>
    </template>
    
    <script>
    export default {
      data () {
        newlist: []
      },
      filters: {
        filterByObj(value, number) {
          console.log(value, number); //items 4
          return value;
        }
      }
    };
    </script>

    reply
    0
  • Cancelreply