Vuejs2 计算属性返回空数组

Vuejs2 计算属性返回空数组,vuejs2,computed-properties,Vuejs2,Computed Properties,我在VueJS中有一个计算属性,如下所示: computed: { groupedTemplates() { const ret = this.templates.reduce((acc, value) => { value.group = value.group || "Ungrouped"; if (!acc[value.group]) { acc[value.group] = [];

我在VueJS中有一个计算属性,如下所示:

  computed: {
    groupedTemplates() {
      const ret = this.templates.reduce((acc, value) => {
        value.group = value.group || "Ungrouped";
        if (!acc[value.group]) {
          acc[value.group] = [];
        }
        acc[value.group].push(value);
        return acc;
      }, []);
      console.log(ret);   // <---- This works!!
      return ret;
    },
    ...mapState(["currentPatient", "currentSite", "phrases", "templates"]),
  },

它像预期的那样返回34。给出了什么?

因为您的
reduce
不会将项目添加到数组中,而是在
array
对象上创建新的属性-您不能添加到数组中


您可能想要的是从您的
groupedTemplates
computed中返回
Object

Wow!太棒了!谢谢但为什么我能用console.log看到它呢?console只是显示了具有所有属性的对象。。。。
return 34;