一、安装axios
(可以参考http://www.axios-js.com/docs/vue-axios.html)
在项目中执行
1 | npm install --save axios vue-axios |
二、在main.js中添加
1 | import Vue from 'vue' |
三、修改配置文件
位于项目根路径下的vue.config.js,与src同级,如果没有则添加。
添加如下配置:
1 | module.exports = { |
四、方法中使用
(可以参考http://www.axios-js.com/docs/vue-axios.html)
1 | this.axios.get("/api/test/hello").then((response) => { |
这里面访问的真实地址就是 http://127.0.0.1:8111/test/hello
或者post请求:
1 | this.axios.post(`/api/test/login`,"username=" + this.loginForm.username + "&password=" + this.loginForm.password) |