Skip to content

Commit 945a6e6

Browse files
committed
add:组件使用axios请求方法,新增代理
1 parent e524905 commit 945a6e6

File tree

4 files changed

+20
-0
lines changed

4 files changed

+20
-0
lines changed

src/App.vue

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
#nav a {
2828
font-weight: bold;
2929
color: #2c3e50;
30+
font-size: 24px;
3031
}
3132
3233
#nav a.router-link-exact-active {

src/components/HelloWorld.vue

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,11 @@ export default {
5656
],
5757
};
5858
},
59+
created() {
60+
this.$http.get("/api/productList").then((res) => {
61+
console.log(res);
62+
});
63+
},
5964
};
6065
</script>
6166
<style scoped>

src/main.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,10 @@ import Vue from "vue";
22
import App from "./App.vue";
33
import router from "./router";
44
import store from "./store";
5+
import axios from "./api/http";
56

67
Vue.config.productionTip = false;
8+
Vue.prototype.$http = axios;
79
// 检查性能-配合Vue Performance Devtool插件使用
810
// 生产上最好关闭
911
Vue.config.performance = true;

vue.config.js

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
module.exports = {
2+
// 选项...
3+
devServer: {
4+
proxy: {
5+
"/api": {
6+
target: "http://172.20.10.5:3999",
7+
changeOrigin: true,
8+
pathRewrite: { "^/api": "" },
9+
},
10+
},
11+
},
12+
};

0 commit comments

Comments
 (0)