feat: 添加环境配置文件,更新API基础地址
This commit is contained in:
@@ -12,23 +12,19 @@ import axios from 'axios' //引入 axios库
|
||||
import qs from 'qs' //引入 node中自带的qs模块(数据格式转换)
|
||||
/* 2.全局默认配置 */
|
||||
let baseURL
|
||||
let process: any = {
|
||||
env: {
|
||||
NODE_ENV: 'development'
|
||||
}
|
||||
}
|
||||
let process: any
|
||||
// 判断开发环境(一般用于本地代理)
|
||||
if (process.env.NODE_ENV === 'development') {
|
||||
// 开发环境
|
||||
baseURL = 'https://api.vvhan.com/' // 你设置的本地代理请求(跨域代理),下文会详细介绍怎么进行跨域代理
|
||||
baseURL = 'http://www.liulongbin.top:3006' // 你设置的本地代理请求(跨域代理),下文会详细介绍怎么进行跨域代理
|
||||
} else {
|
||||
// 编译环境
|
||||
if (process.env.type === 'test') {
|
||||
// 测试环境
|
||||
baseURL = 'https://api.vvhan.com/'
|
||||
baseURL = 'http://www.liulongbin.top:3006'
|
||||
} else {
|
||||
// 正式环境
|
||||
baseURL = 'https://api.vvhan.com/'
|
||||
baseURL = 'http://www.liulongbin.top:3006'
|
||||
}
|
||||
}
|
||||
// 配置axios的属性
|
||||
@@ -67,7 +63,6 @@ Axios.interceptors.request.use(
|
||||
return Promise.reject(error)
|
||||
}
|
||||
)
|
||||
|
||||
Axios.interceptors.response.use(
|
||||
(res) => {
|
||||
//请求响应后拦截
|
||||
|
||||
@@ -1,4 +1,12 @@
|
||||
// import path from 'node:path/win32'
|
||||
/*
|
||||
* @Description: {{ByRuin}}
|
||||
* @Version: 2.0
|
||||
* @Author: Ruin 🍭
|
||||
* @Date: 2022-01-25 16:57:54
|
||||
* @LastEditors: 刘引
|
||||
* @LastEditTime: 2022-03-11 14:26:24
|
||||
*/
|
||||
import path from 'node:path/win32'
|
||||
import { createRouter, createWebHashHistory } from 'vue-router'
|
||||
const routes = [
|
||||
{
|
||||
@@ -24,3 +32,4 @@ const router = createRouter({
|
||||
routes
|
||||
})
|
||||
export default router
|
||||
// 我感觉
|
||||
|
||||
@@ -1,26 +1,47 @@
|
||||
import Axios from '@/api/base-service' // 导入配置好的axios文件
|
||||
// 封装axios请求函数,并用export导出
|
||||
// get请求
|
||||
const getInfo = (params: unknown) => {
|
||||
return Axios({
|
||||
url: '/api/horoscope',
|
||||
method: 'get',
|
||||
headers: {
|
||||
'Content-Type': 'application/x-www-form-urlencoded' //设置请求头请求格式form
|
||||
},
|
||||
params
|
||||
})
|
||||
}
|
||||
/*
|
||||
* @Description: {{ByRuin}}
|
||||
* @Version: 2.0
|
||||
* @Author: Ruin 🍭
|
||||
* @Date: 2022-01-25 17:42:57
|
||||
* @LastEditors: 刘引
|
||||
* @LastEditTime: 2022-01-25 18:04:29
|
||||
*/
|
||||
|
||||
// post请求
|
||||
const getItem = (data: unknown) => {
|
||||
import Axios from "../api/base-service"; // 导入配置好的axios文件
|
||||
// 封装axios请求函数,并用export导出
|
||||
export function getInfo(datas: unknown) {
|
||||
return Axios({
|
||||
url: '/api/getItem',
|
||||
method: 'post',
|
||||
url: "/api.php?key=free&appid=0&msg=鹅鹅鹅",
|
||||
method: "GET",
|
||||
headers: {
|
||||
'Content-Type': 'application/json' //设置请求头请求格式为json
|
||||
"content-type": "application/json",
|
||||
},
|
||||
data
|
||||
})
|
||||
data: datas,
|
||||
});
|
||||
}
|
||||
export function getInfoA(datas: unknown) {
|
||||
return Axios({
|
||||
url: "/api/getbooks",
|
||||
method: "get",
|
||||
headers: {
|
||||
"Content-Type": "application/x-www-form-urlencoded", //设置请求头请求格式form
|
||||
},
|
||||
data: datas,
|
||||
});
|
||||
}
|
||||
export function getItem(datas: unknown) {
|
||||
return Axios({
|
||||
url: "/api/getItem",
|
||||
method: "post",
|
||||
headers: {
|
||||
"Content-Type": "application/json", //设置请求头请求格式为json
|
||||
},
|
||||
data: datas,
|
||||
});
|
||||
}
|
||||
export function getItemInfo(datas: unknown) {
|
||||
return Axios({
|
||||
url: "/api/getItemInfo" + datas,
|
||||
method: "get",
|
||||
});
|
||||
}
|
||||
export { getInfo, getItem }
|
||||
|
||||
13
src/utils/other.ts
Normal file
13
src/utils/other.ts
Normal file
@@ -0,0 +1,13 @@
|
||||
/*
|
||||
* @Description: {{ByRuin}}
|
||||
* @Version: 2.0
|
||||
* @Author: Ruin 🍭
|
||||
* @Date: 2022-01-25 17:45:05
|
||||
* @LastEditors: 刘引
|
||||
* @LastEditTime: 2022-01-25 17:47:27
|
||||
*/
|
||||
import axios from "axios";
|
||||
const otherApi = axios.create({
|
||||
baseURL: "http://baidu.com",
|
||||
});
|
||||
export default otherApi;
|
||||
13
src/utils/request/request.ts
Normal file
13
src/utils/request/request.ts
Normal file
@@ -0,0 +1,13 @@
|
||||
/*
|
||||
* @Description: {{ByRuin}}
|
||||
* @Version: 2.0
|
||||
* @Author: Ruin 🍭
|
||||
* @Date: 2022-01-25 17:36:26
|
||||
* @LastEditors: 刘引
|
||||
* @LastEditTime: 2022-01-25 17:46:39
|
||||
*/
|
||||
import axios from 'axios'
|
||||
const homeApi = axios.create({
|
||||
baseURL: 'http://baidu.com'
|
||||
})
|
||||
export default homeApi
|
||||
@@ -1,3 +1,11 @@
|
||||
<!--
|
||||
* @Description: {{ByRuin}}
|
||||
* @Version: 2.0
|
||||
* @Author: Ruin 🍭
|
||||
* @Date: 2022-03-10 10:11:06
|
||||
* @LastEditors: 刘引
|
||||
* @LastEditTime: 2022-07-26 14:42:06
|
||||
-->
|
||||
<template>
|
||||
<div class="root-home">
|
||||
<p>我是home组件</p>
|
||||
@@ -6,33 +14,9 @@
|
||||
</div>
|
||||
</template>
|
||||
<script setup lang="ts">
|
||||
import { computed, watch, onUpdated, ref, reactive, onBeforeMount } from 'vue'
|
||||
import { computed, watch, onUpdated, ref, reactive } from 'vue';
|
||||
import news from './components/news.vue'
|
||||
import { getInfo, getItem } from '@/services/home'
|
||||
|
||||
// get请求
|
||||
const getDataFromApi = async () => {
|
||||
try {
|
||||
const res = await getInfo({ type: 'scorpio', time: 'today' })
|
||||
console.debug(res, '获取到的数据')
|
||||
} catch (error) {
|
||||
console.error('get获取星座数据报错', error)
|
||||
}
|
||||
}
|
||||
|
||||
// post请求
|
||||
const postDataFromApi = async () => {
|
||||
try {
|
||||
} catch (error) {
|
||||
console.error('post获取数据报错', error)
|
||||
}
|
||||
}
|
||||
|
||||
// dom加载前调用
|
||||
onBeforeMount(() => {
|
||||
// getDataFromApi()
|
||||
// postDataFromApi()
|
||||
})
|
||||
</script>
|
||||
|
||||
<style lang="scss" scoped></style>
|
||||
<style lang="scss" scoped>
|
||||
</style>
|
||||
@@ -1,15 +1,12 @@
|
||||
<template>
|
||||
<Head></Head>
|
||||
<div>根组件{{ store.count }}</div>
|
||||
<home></home>
|
||||
<Foot></Foot>
|
||||
</template>
|
||||
|
||||
<script setup lang="ts">
|
||||
import { reactive, onMounted, watch } from 'vue'
|
||||
import { useMain } from '@/store'
|
||||
import home from '@/views/home/index.vue'
|
||||
|
||||
const store = useMain()
|
||||
</script>
|
||||
|
||||
|
||||
@@ -1,3 +1,11 @@
|
||||
<!--
|
||||
* @Description: {{ByRuin}}
|
||||
* @Version: 2.0
|
||||
* @Author: Ruin 🍭
|
||||
* @Date: 2022-03-10 10:11:06
|
||||
* @LastEditors: 刘引 liu.yin.work@foxmail.com
|
||||
* @LastEditTime: 2023-08-01 15:45:57
|
||||
-->
|
||||
<template>
|
||||
<div class="root-home">
|
||||
<news></news>
|
||||
|
||||
Reference in New Issue
Block a user