Is there a way in vuejs like angularjs filter
高洛峰
高洛峰 2017-05-19 10:29:06
0
5
621

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中如果写过虑器
高洛峰
高洛峰

拥有18年软件开发和IT教学经验。曾任多家上市公司技术总监、架构师、项目经理、高级软件工程师等职务。 网络人气名人讲师,...

reply all(5)
迷茫

Reference stamp

伊谢尔伦

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

淡淡烟草味

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() {}
迷茫

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

習慣沉默

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>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template