When the button is clicked for the first time and the data property is empty, I need to pause the button click code until an ajax response is received.
Currently, when I press the button, both wait
and scroll
actions happen immediately without waiting for the response.
<template>
<div class="FinanceSlider">
<div class="BudgetSlider">
<div class="ShowPayments">
<a href="javascript:void(0)"
@click="focus"
class="btn--secondary"
title="See my payments">
<span class="ci-spinner spin" v-if="loading"></span>See my payments
</a>
</div>
</div>
</div>
</template>
<script>
import Axios from "axios";
export default {
data () {
return {
quote: null
}
},
methods: {
focus: async function () {
// Wait for a quote before scrolling to it.
if (!this.quote) {
console.log('wait');
await this.getQuote();
}
// Already has data, scroll to it.
console.log('scroll')
},
getQuote: function() {
this.loading = true;
Axios.post('credit-calculator/calculate', {}).then(response => {
this.loading = false;
if (response.data) {
window.EventBus.$emit('finance-calculator-display', response.data);
}
return true;
});
}
}
}
</script>