I use axios http client in vuejs application and this code:
axios.get('http://localhost:8081/pets')
.then(response => {
this.pets = response.data;
})
If server return simple "application/json" conten, then all fine. But i want read "application/stream+json" for each row separately.
For example:
axios.get('http://localhost:8081/pets')
.then(response => {
this.pets.push(response.data)
})
But this code (as expected) does not work.
Axios is an Excellent HTTP library that executes on both client and a server, which makes an API request, does the task to produce the result and specifies easier concepts to read and debug. Vue. js is the front-end JavaScript Framework to build tools and libraries. The Axios works well in the platform like node.
To access external JSON file objects in Vue. js app, we can import the JSON with import and then use that as the value of a reactive property. to import the json array from the ./json/data.
Vue Fetch data from API example To get the actual JSON body of the response, we use response. json() method. We can also access metadata such as headers , status , statusText , type , url from the Response object. The response Promise does not reject on HTTP errors (for example: 404 , 500 ).
I solved this problem with SSE:
let es = new EventSource('http://localhost:8081/pets');
es.addEventListener('message', event => {
let data = JSON.parse(event.data);
this.pets.push(data);
}, false);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With