Currently, I am utilizing VUE and Axios to retrieve a JSON from an API. However, I encountered an issue when attempting to assign the received results from the API into a variable outside the Vue Instance as it is showing that the item is null. (When I check in the console by calling vueinstance.results, I do get the results).
var vueinstance = new Vue({
el: '#app',
data(){
return {results: null }
} ,
methods: {
callApiSearch: function (searchQuery) {
axios
.post('api/search', searchQuery)
.then(response => (this.results = response.data))
}
}
});
var ajaxSearch = function callApi(searchQuery) {
//Construct Search Query
if (typeof searchQuery === "string" || searchQuery instanceof String) {
searchQuery = { Query: searchQuery };
}
vueinstance.callApiSearch(searchQuery);
var test = vueinstance.results; <====== **THE VALUE HERE IS RETURNING AS NULL**
}
If anyone has any insights on how to resolve this issue, your assistance would be greatly appreciated. Thank you.