From ed42b204d7f8f39a91d05f6158ad02c3fbb5f3a2 Mon Sep 17 00:00:00 2001 From: luyuan <1162963624@qq.com> Date: Thu, 24 Sep 2020 15:33:12 +0800 Subject: [PATCH] =?UTF-8?q?=E6=B7=BB=E5=8A=A0=E4=BA=86=E6=8B=A6=E6=88=AA?= =?UTF-8?q?=E5=99=A8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- package.json | 1 - src/api/base.ts | 21 +++++++++++++++++++++ src/api/index.ts | 10 ++++++++++ src/config/axiosConfig.ts | 4 +--- src/main.ts | 6 ++---- src/views/Home.vue | 7 +++++++ tsconfig.json | 1 + yarn.lock | 5 ----- 8 files changed, 42 insertions(+), 13 deletions(-) create mode 100644 src/api/base.ts create mode 100644 src/api/index.ts diff --git a/package.json b/package.json index c3e1f56..2c99d69 100644 --- a/package.json +++ b/package.json @@ -12,7 +12,6 @@ "axios": "^0.20.0", "core-js": "^3.6.5", "vue": "^3.0.0-0", - "vue-axios": "^2.1.5", "vue-router": "^4.0.0-0", "vuex": "^4.0.0-0" }, diff --git a/src/api/base.ts b/src/api/base.ts new file mode 100644 index 0000000..e1de090 --- /dev/null +++ b/src/api/base.ts @@ -0,0 +1,21 @@ +import axios from '../config/axiosConfig' +import { AxiosPromise } from 'axios'; + +axios.interceptors.response.use((response)=>{ + return response.data; +},(error)=>{ + return error; +}) + +function get(url: string,data?: object): Promise { + return axios.get(url,{params:data}) +} + +function post(url: string,data?: object): Promise { + return axios.post(url,data) +} + +export { + get, + post +} \ No newline at end of file diff --git a/src/api/index.ts b/src/api/index.ts new file mode 100644 index 0000000..f578d7e --- /dev/null +++ b/src/api/index.ts @@ -0,0 +1,10 @@ +import { get, post } from './base' +import { AxiosPromise } from 'axios' + +export function getinfo(): Promise{ + return get("a") +} + +export function seninfo(data: object | undefined): Promise{ + return post("b",data) +} diff --git a/src/config/axiosConfig.ts b/src/config/axiosConfig.ts index 69bc059..3fb503d 100644 --- a/src/config/axiosConfig.ts +++ b/src/config/axiosConfig.ts @@ -1,8 +1,6 @@ import axios from 'axios' -axios.defaults.baseURL = 'https://api.example.com'; +axios.defaults.baseURL = 'https://theluyuan.com/api/'; axios.defaults.headers.common['Authorization'] = 'token'; axios.defaults.headers.post['Content-Type'] = 'application/x-www-form-urlencoded'; - - export default axios \ No newline at end of file diff --git a/src/main.ts b/src/main.ts index a8fc2da..4b24106 100644 --- a/src/main.ts +++ b/src/main.ts @@ -4,8 +4,6 @@ import Antd from 'ant-design-vue'; import router from './router' import store from './store' import 'ant-design-vue/dist/antd.css'; -import axios from "./config/axiosConfig" -import VueAxios from "vue-axios" - -createApp(App).use(store).use(router).use(Antd).use(VueAxios,axios).mount('#app') +const app = createApp(App); +app.use(store).use(router).use(Antd).mount('#app') diff --git a/src/views/Home.vue b/src/views/Home.vue index 50d8a19..5d17639 100644 --- a/src/views/Home.vue +++ b/src/views/Home.vue @@ -8,11 +8,18 @@ diff --git a/tsconfig.json b/tsconfig.json index e621cbc..931f75e 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -11,6 +11,7 @@ "allowSyntheticDefaultImports": true, "sourceMap": true, "baseUrl": ".", + "noImplicitThis": true, "types": [ "webpack-env" ], diff --git a/yarn.lock b/yarn.lock index 63e5464..0b709d3 100644 --- a/yarn.lock +++ b/yarn.lock @@ -8726,11 +8726,6 @@ vm-browserify@^1.0.1: resolved "https://registry.npmjs.org/vm-browserify/-/vm-browserify-1.1.2.tgz#78641c488b8e6ca91a75f511e7a3b32a86e5dda0" integrity sha512-2ham8XPWTONajOR0ohOKOHXkm3+gaBmGut3SRuu75xLd/RRaY6vqgh8NBYYk7+RW3u5AtzPQZG8F10LHkl0lAQ== -vue-axios@^2.1.5: - version "2.1.5" - resolved "https://registry.npm.taobao.org/vue-axios/download/vue-axios-2.1.5.tgz#1af4bf1218ed71309c76afb38d0f683e312c24a7" - integrity sha1-GvS/EhjtcTCcdq+zjQ9oPjEsJKc= - vue-eslint-parser@^7.0.0, vue-eslint-parser@^7.1.0: version "7.1.0" resolved "https://registry.npmjs.org/vue-eslint-parser/-/vue-eslint-parser-7.1.0.tgz#9cdbcc823e656b087507a1911732b867ac101e83"