Vue.js 在 v-for 中重写 orderBy 过滤器

Posted

技术标签:

【中文标题】Vue.js 在 v-for 中重写 orderBy 过滤器【英文标题】:Vue.js rewriting orderBy Filter in v-for 【发布时间】:2020-05-15 09:38:10 【问题描述】:

由于在 vue.js v-2 中删除了 orderBy 过滤器,我现在想知道如何重写此代码部分:

<li class="day" v-for="day in days | orderBy 'unix' 1" v-bind:class=" 'outside': day.outsideOfCurrentMonth, 'empty': day.events.length === 0 ">

我想写

<li class="day" v-for="day in orderedDays">

但不知道括号里写什么,orderBy()写什么:

computed: 
  orderedDays: function () 
    return _.orderBy()
  

Here 是完整的组件。 有人可以帮忙吗?

【问题讨论】:

这能回答你的问题吗? Vue.js: can't orderBy in v-for 【参考方案1】:
<li class="day" v-for="day in orderedDays">
computed: 
  orderedDays: function () 
    return _.orderBy(this.days, ['unix'], ['asc'])
  

【讨论】:

以上是关于Vue.js 在 v-for 中重写 orderBy 过滤器的主要内容,如果未能解决你的问题,请参考以下文章