April 2017
Intermediate to advanced
454 pages
12h 51m
English
Another way to approach the same problem is to use Axios for sending the AJAX request. If you need to brush up on what Axios is, take a look at the Sending basic AJAX requests with Axios recipe.
The code for the submit method will become as follows (remember to add Axios as a dependency):
submit () { axios.post('http://jsonplaceholder.typicode.com/posts', { title: this.title, body: this.body, userId: this.userId }).then(response => { this.response = JSON.stringify(response,null,' ') }).catch(error => { this.response = 'Error: ' + error.response.status }) }
This code is perfectly equivalent, but it's much more expressive and concise than using native browser objects.
Read now
Unlock full access