Reputation: 25
I have working example from official site.
computed: { filteredData: function () {} )
How to get filteredData (computed property) globally? Espiccially if I want to send it somewhere else. demo.$store contains only original properties, not computed. I see the only way to achieve this is demo.$children[0].filteredData. But that is not pure. By the way, im using vuex.
Upvotes: 2
Views: 2287
Reputation: 4025
Computed data is only available to the current component. However you can use getters in Vuex and import that as computed property where ever is needed.
In vuex, you declare this:
getters: {
filteredData (state) {
return state.data.filter(x => x)
}
}
and then, where you require it, you just imported:
import { mapGetters } from 'vuex'
export default {
// ...
computed: {
...mapGetters({
filteredData
})
}
// ...
}
Upvotes: 1