What is the simplest way to initialize data in a Vue component from an async api call in a vuex store. The component mounts before the data is available.
Consider:
export default {
data () {
return {
loanAmount: 300000,
thirtyFixedAPR: null,
fifteenFixedAPR: null,
fiveArmAPR: null
}
},
methods: {
fetchRates () {
this.thirtyFixedAPR = this.$store.state.rates.thirtyFixed.apr
this.fifteenFixedAPR = this.$store.state.rates.fifteenFixed.apr
this.fiveArmAPR = this.$store.state.rates.fiveArm.apr
}
},
mounted () {
this.fetchRates()
}}
I want to call the fetchRates method once after the api call in the vuex store is finished. I'd use a computed property but I only want to initialize the data, not watch it. I've experimented with a few workarounds using watchers that don't seem very elegant and I have a feeling there is a simpler answer to this.
Thanks for your help.