Skip to content

Commit 4c80b2b

Browse files
Add axios dependencies and wrap it reusable.
1 parent 4ad0491 commit 4c80b2b

File tree

8 files changed

+82
-186
lines changed

8 files changed

+82
-186
lines changed

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
},
1212
"dependencies": {
1313
"@mdi/font": "^4.7.95",
14+
"axios": "^0.19.0",
1415
"core-js": "^3.3.2",
1516
"material-design-icons-iconfont": "^5.0.1",
1617
"vue": "^2.6.10",

src/components/base/portrait/Portrait.vue

Lines changed: 2 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<template>
22
<v-card class="portrait">
3-
<!-- <v-card-title class="cyan darken-1">
3+
<v-card-title class="cyan darken-1">
44
<span class="headline white--text">Sarah Mcbeal</span>
55

66
<v-spacer></v-spacer>
@@ -19,7 +19,7 @@
1919
icon>
2020
<v-icon>mdi-dots-vertical</v-icon>
2121
</v-btn>
22-
</v-card-title> -->
22+
</v-card-title>
2323

2424
<v-img :src="imageSrc"
2525
height="200px"></v-img>
@@ -44,44 +44,6 @@
4444
:key="'divider'+ i"
4545
inset></v-divider>
4646
</template>
47-
48-
<!-- <v-list-item>
49-
<v-list-item-action>
50-
<v-icon>mdi-phone</v-icon>
51-
</v-list-item-action>
52-
53-
<v-list-item-content>
54-
<v-list-item-title>(323) 555-6789</v-list-item-title>
55-
</v-list-item-content>
56-
57-
<v-list-item-action>
58-
<v-icon>mdi-message-text</v-icon>
59-
</v-list-item-action>
60-
</v-list-item>
61-
62-
<v-divider inset></v-divider>
63-
64-
<v-list-item>
65-
<v-list-item-action>
66-
<v-icon>mdi-email</v-icon>
67-
</v-list-item-action>
68-
69-
<v-list-item-content>
70-
<v-list-item-title>mcbeal@example.com</v-list-item-title>
71-
</v-list-item-content>
72-
</v-list-item>
73-
74-
<v-divider inset></v-divider>
75-
76-
<v-list-item>
77-
<v-list-item-action>
78-
<v-icon>mdi-map-marker</v-icon>
79-
</v-list-item-action>
80-
81-
<v-list-item-content>
82-
<v-list-item-title>Orlando, FL 79938</v-list-item-title>
83-
</v-list-item-content>
84-
</v-list-item> -->
8547
</v-list>
8648

8749
</v-card>

src/pages/generic/cta/Cta.ts

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,9 @@
11
import { Component, Vue, Prop, Watch, Emit } from 'vue-property-decorator';
2-
2+
import { requestGet } from '@/plugins/axios-handler';
33
@Component({})
4-
export default class Cta extends Vue {}
4+
export default class Cta extends Vue {
5+
6+
private hello() {
7+
requestGet('aaaa', { x: 'a', y: 'b' });
8+
}
9+
}

src/pages/generic/cta/Cta.vue

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
bottom
55
right
66
color="secondary"
7-
href="https://github.com/vuetifyjs/theme-blog"
7+
@click="hello()"
88
target="_blank"
99
rel="noopener">
1010
<v-icon>mdi-download</v-icon>
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
import { AxiosRequestConfig } from 'axios';
2+
3+
const config: AxiosRequestConfig = {};
4+
5+
if (process.env.NODE_ENV === 'development') {
6+
config.baseURL = 'https://some-domain.com/api/';
7+
config.timeout = 1000;
8+
config.headers = { 'X-Custom-Header': 'foobar' };
9+
}
10+
11+
if (process.env.NODE_ENV === 'prodction') {
12+
config.baseURL = 'https://some-domain.com/api/';
13+
config.timeout = 1000;
14+
config.headers = { 'X-Custom-Header': 'foobar' };
15+
}
16+
17+
export default config;

src/plugins/axios-handler/index.ts

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
// 默认利用axios的cancelToken进行防重复提交。
2+
// 如需允许多个提交同时发出。则需要在请求配置config中增加 neverCancel 属性,并设置为true
3+
import axios from 'axios';
4+
import baseConfig from './axiosrc';
5+
import { Vue } from 'vue-property-decorator';
6+
// define AJAX params that should be a key value pair
7+
interface params {
8+
[key: string]: any
9+
}
10+
11+
function createInstance (params ? : params, timeout ? : number) {
12+
if (params !== undefined) baseConfig.params = params;
13+
if (timeout !== undefined) baseConfig.timeout = timeout;
14+
15+
return axios.create(baseConfig);
16+
}
17+
18+
export function requestGet (url: string, params ? : params) {
19+
return createInstance(params).get(url);
20+
}
21+
22+
export function requestPost (url: string, params ? : params) {
23+
return createInstance(params).post(url);
24+
}

src/plugins/router/index.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@ for (let index in routeConfs) {
2121
if (routeConfs[index] !== null) {
2222
routes.push(routeConfs[index]);
2323
}
24-
2524
}
2625

2726
routes.push({

0 commit comments

Comments
 (0)