diff --git a/src/api/register/index.ts b/src/api/register/index.ts index 22f76ce..3819f2c 100644 --- a/src/api/register/index.ts +++ b/src/api/register/index.ts @@ -3,10 +3,10 @@ import { IUserModel } from '@/api-types/user' const request = useAxios() -export const getCodeApi = () => { - return request.get>({ url: 'user/captcha' }) +export const getCodeApi = async () => { + return (await request.get>({ url: 'user/captcha' })).data } -export const registerApi = (data: Omit) => { - return request.post>({ url: 'user/register', data }) +export const registerApi = async (data: Omit) => { + return (await request.post>({ url: 'user/register', data })).data } diff --git a/src/config/axios/index.ts b/src/config/axios/index.ts index c55557e..ee90740 100644 --- a/src/config/axios/index.ts +++ b/src/config/axios/index.ts @@ -1,10 +1,4 @@ -import axios, { - AxiosInstance, - AxiosRequestConfig, - AxiosRequestHeaders, - AxiosResponse, - AxiosError -} from 'axios' +import axios, { AxiosInstance, AxiosRequestConfig, AxiosResponse, AxiosError } from 'axios' import { ElMessage } from 'element-plus' @@ -27,8 +21,7 @@ service.interceptors.request.use( (config: AxiosRequestConfig) => { if ( config.method === 'post' && - (config.headers as AxiosRequestHeaders)['Content-Type'] === - 'application/x-www-form-urlencoded' + config!.headers!['Content-Type'] === 'application/x-www-form-urlencoded' ) { config.data = qs.stringify(config.data) } diff --git a/src/hooks/web/useAxios.ts b/src/hooks/web/useAxios.ts index 7743870..e5caf69 100644 --- a/src/hooks/web/useAxios.ts +++ b/src/hooks/web/useAxios.ts @@ -6,7 +6,7 @@ import { config } from '@/config/axios/config' const { default_headers } = config -const request = (option: AxiosConfig): AxiosPromise => { +const request = (option: AxiosConfig) => { const { url, method, params, data, headersType, responseType } = option return service({ url: url, @@ -21,19 +21,19 @@ const request = (option: AxiosConfig): AxiosPromise => { } function getFn(option: AxiosConfig): AxiosPromise { - return request({ method: 'get', ...option }) + return request({ method: 'get', ...option }) } function postFn(option: AxiosConfig): AxiosPromise { - return request({ method: 'post', ...option }) + return request({ method: 'post', ...option }) } function deleteFn(option: AxiosConfig): AxiosPromise { - return request({ method: 'delete', ...option }) + return request({ method: 'delete', ...option }) } function putFn(option: AxiosConfig): AxiosPromise { - return request({ method: 'put', ...option }) + return request({ method: 'put', ...option }) } export const useAxios = () => { diff --git a/src/views/Login/components/RegisterForm.vue b/src/views/Login/components/RegisterForm.vue index 73f267b..65ad3bf 100644 --- a/src/views/Login/components/RegisterForm.vue +++ b/src/views/Login/components/RegisterForm.vue @@ -131,8 +131,8 @@ const toLogin = () => { const codeUrl = ref('') const getCode = async () => { - const { data } = await getCodeApi() - codeUrl.value = data.result + const { result } = await getCodeApi() + codeUrl.value = result } getCode() @@ -145,8 +145,8 @@ const loginRegister = async () => { try { loading.value = true const formData = await getFormData>() - const { data } = await registerApi(formData) - if (data) { + const { result } = await registerApi(formData) + if (result) { ElMessage.success('注册成功') toLogin() }