2017-08-07 98 views
0

,我在一個應用程序中使用VuexFire和在我的組件https://github.com/posva/vuexfire我有一個像VuexFire:如何合併計算:和()計算

computed: Vuex.mapGetters(['todos']), 
    created() { 
    this.$store.dispatch('setTodosRef', todosRef) 
    }, 

這個工程除了當我也有一些計算方法細紋在這種情況下,我不知道該怎麼做。我已經嘗試了諸如:

computed: Vuex.mapGetters(['todos']), 
    computed() { 
     amethod: { return 1 } 
    }, 
    created() { 
    this.$store.dispatch('setTodosRef', todosRef) 
    }, 

computed() { 
     amethod: { return 1 } 
    }, 
    created() { 
    ...Vuex.mapGetters(['todos']) 
    this.$store.dispatch('setTodosRef', todosRef) 
    }, 

但這些了,我已經嘗試了其他的東西,顯然是誤導,因爲他們沒有工作(即數據從火力不可用的方法。

什麼是正確的做法?

回答

1

首先,你將永遠指定計算屬性的對象,而不是一個方法(如你正在做無線th computed())。

其次,你需要在computed對象使用spread operator

computed: { 
    amethod() { return 1 }, 
    ...Vuex.mapGetters(['todos']) 
} 

這有效地展開全部由Vuex.mapGetters返回的計算特性的方法和將它們定義爲computed對象的屬性。

+0

非常感謝。不知道爲什麼我不試試這個! – Andrew