import axios in vue3 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: use $axios in vuex in nuxt
async nuxtServerInit ({ commit }, { $axios }) {
const ip = await $axios.$get('http://icanhazip.com')
commit('SET_IP', ip)
}