Skip to content

Commit b776d13

Browse files
committed
修改axios文件
1 parent fba175b commit b776d13

File tree

3 files changed

+67
-5
lines changed

3 files changed

+67
-5
lines changed

src/api/dev.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
export default {
2-
prefix: 'http://dev.com/',
2+
prefix: 'http://www.localhost:7001',
33
iamPrefix: 'https://dev.com:9002/',
44
filefix: 'http://dev.com/',
55
};

src/utils/axios-config.ts

Lines changed: 61 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
* @Company:
77
* @Date: 2019-08-16 16:57:42
88
* @LastEditors: 水痕
9-
* @LastEditTime: 2019-08-16 17:30:10
9+
* @LastEditTime: 2019-08-21 10:21:16
1010
*/
1111

1212
import axios from 'axios';
@@ -59,9 +59,7 @@ export const axiosConfig = (): void => {
5959

6060
/********************************请求响应的 start********************************/
6161
function response(res: any) {
62-
return isPlainRequest(res.config.url) || useOrigin(response)
63-
? res
64-
: res.data;
62+
return isPlainRequest(res.config.url) || useOrigin(res) ? res : res.data;
6563
}
6664
function responseError(error: any) {
6765
return Promise.reject(error);
@@ -73,3 +71,62 @@ export const axiosConfig = (): void => {
7371
// 拦截响应
7472
axios.interceptors.response.use(response, responseError);
7573
};
74+
75+
// class AxiosRequest {
76+
// private baseUrl: string;
77+
// private timeout: number;
78+
// constructor(baseUrl: string = prefix, timeout: number = 60 * 1000) {
79+
// this.baseUrl = baseUrl;
80+
// this.timeout = timeout;
81+
// }
82+
83+
// public request(config: { [propsName: string]: any }) {
84+
// const instance = axios.create({
85+
// baseURL: this.baseUrl,
86+
// timeout: this.timeout,
87+
// });
88+
// /********************************设置请求拦截 start********************************/
89+
// instance.interceptors.request.use(this.requestSuccess, this.requestError);
90+
// /********************************设置请求拦截 end********************************/
91+
// /********************************设置响应拦截 start********************************/
92+
// instance.interceptors.response.use(
93+
// this.responseSuccess,
94+
// this.responseError,
95+
// );
96+
// /********************************设置响应拦截 end********************************/
97+
// return instance(config);
98+
// }
99+
100+
// private requestSuccess(config: { [propsName: string]: any }) {
101+
// config.headers['X-Origin'] = 'admin-web';
102+
// config.headers[authToken] = storage.getItem(authToken);
103+
// config.headers[authMobile] = storage.getItem(authMobile);
104+
// return config;
105+
// }
106+
107+
// private requestError(rejection: { data: any }) {
108+
// return this.useOrigin(rejection)
109+
// ? Promise.reject(rejection)
110+
// : Promise.reject(rejection.data);
111+
// }
112+
113+
// private responseSuccess(res: any): any {
114+
// return this.isPlainRequest(res.config.url) || this.useOrigin(res)
115+
// ? res
116+
// : res.data;
117+
// }
118+
119+
// private responseError(error: any) {
120+
// return Promise.reject(error);
121+
// }
122+
123+
// private useOrigin(res: any) {
124+
// return res.config.useOrigin;
125+
// }
126+
127+
// private isPlainRequest(input: string) {
128+
// return /\.(html?|xml|txt)$/.test(input);
129+
// }
130+
// }
131+
132+
// export const axiosConfig = new AxiosRequest();

src/views/shared/login/Login.vue

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@
4646
import { Component, Vue, Provide } from 'vue-property-decorator';
4747
import { OperatedProduct } from '@/config';
4848
import { storage } from '@/utils';
49+
import axios from 'axios';
4950
5051
@Component({})
5152
export default class Login extends Vue {
@@ -56,6 +57,10 @@ export default class Login extends Vue {
5657
private submitForm(formType: string): void {
5758
(this.$refs[formType] as any).validate((valid: boolean) => {
5859
if (valid) {
60+
console.log('--------')
61+
axios.post('/api/v1/user/login', { userName: this.loginForm.email, password: this.loginForm.password }).then((data: any) => {
62+
console.log(data);
63+
});
5964
// 设置本地存储
6065
storage.setItem(OperatedProduct, this.loginForm.email);
6166
if (this.$route.query.backUrl) {

0 commit comments

Comments
 (0)