vuejs simple rest call code example
Example 1: axios in vue
//Install Axios
npm install axios
//Import Axios in .vue file
import axios from 'axios'
//Add a method to implement Axios
testMethod () {
axios.post('URL')
.then(function (response) {
alert (response.data);
})
.catch(function (error) {
alert(error);
});
}
Example 2: vue fetch api
async created() {
// GET request using fetch with async/await
const response = await fetch("https://api.npms.io/v2/search?q=vue");
const data = await response.json();
this.totalVuePackages = data.total;
}