1//Install Axios
2npm install axios
3
4//Import Axios in .vue file
5import axios from 'axios'
6
7//Add a method to implement Axios
8testMethod () {
9 axios.post('URL')
10 .then(function (response) {
11 alert (response.data);
12 })
13 .catch(function (error) {
14 alert(error);
15 });
16 }
1<template>
2 <form class="" method="post" @submit.prevent="postNow">
3 <input type="text" name="" value="" v-model="name">
4 <button type="submit" name="button">Submit</button>
5 </form>
6</template>
7
8export default {
9 name: 'formPost',
10 data() {
11 return {
12 name: '',
13 show: false,
14 };
15 },
16 methods: {
17 postNow() {
18 axios.post('http://localhost:3030/api/new/post', {
19 headers: {
20 'Content-type': 'application/x-www-form-urlencoded',
21 },
22 body: this.name,
23 });
24 },
25 components: {
26 Headers,
27 Footers,
28 },
29};
1//Install Axios from terminal
2npm install axios
3//Import Axios in your HelloWorld.vue
4import axios from 'axios'
5//Add a method to implement Axios
6test () {
7 axios.post('URL')
8 .then(function (response) {
9 alert (response.data);
10 })
11 .catch(function (error) {
12 alert(error);
13 });
14 }