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中如果写过虑器
淡淡烟草味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() {}
迷茫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.
習慣沉默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>