使用步骤
1、命令行中安装axios
npm install axios
2、main.js文件中引入
import axios from 'axios'
Vue.prototype.$axios = axios
3、vue页面中使用
this.$axios.post('http://localhost:8080/reqParams', this.map)
.then((res) => {
console.log(res)
})
.catch((err) => {
console.log(err)
})
第二步、第三步要对应 [$axios],不然会找不到
遇到的错误有下面两种:
Uncaught (in promise) TypeError: Cannot read property 'protocol' of undefined
Error in v-on handler: "TypeError: Cannot read property 'post' of undefined"