How to access `PromiseValue` in axios `response` in VueJs
You cannot assign the Axios call to a variable while using Promises (unless you are using await/async).
Instead you should be running the logic within the then
callback. Otherwise to the synchronous nature of JavaScript it will run before the request has completed. Your code should look something like this:
methods:{ showDetails(id){ axios.get('/api/clients/'+row.id).then(response => { //Logic goes here this.singleData = response.data this.leftPanelVisibility = true }).catch(error => { alert(error); }); }}
You need to assign a variable the response of your axios:
showDetails(id){ axios.get('/api/clients/'+id) .then(function (response) { this.singleData = response.data; }).catch(error => { alert(error); }); console.log(this.sigleData); this.leftPanelVisiblity = true },