I've got this Vue.js code below which has a variable newQuestion
which I send to the function get answer like so this.getAnswer(newQuestion)
where further along down in the methods as this line getAnswer: _.debounce(
I would like to access it so I can insert it here axios.post('http://35.196.91.194/insurance-list', {})
as part of the values sent in the post.
The full code below
var InsuranceVM = new Vue({
delimiters: ['[[', ']]'],
el: '#insurance-form',
data: {
insurance_types: [],
insurance_type: '',
insurance_types_get_error: '',
},
watch: {
// whenever question changes, this function will run
insurance_type: function (newQuestion, oldQuestion) {
//this.answer = 'Waiting for you to stop typing...'
this.getAnswer(newQuestion)
}
},
methods: {
getAnswer: _.debounce(
function () {
var vm = this;
axios.post('http://35.196.91.194/insurance-list', {})
.then(function (response) {
vm.insurance_types_get_error = '';
vm.insurance_types = response.data.results;
})
.catch(function (error) {
vm.insurance_types_get_error = 'Error! Could not reach the API. ' + error;
})
},
500
)
}
});