模板请求处理

This commit is contained in:
2023-12-13 17:27:24 +08:00
parent dfa6146840
commit 26a6d313e3
14 changed files with 119 additions and 80 deletions

8
.idea/.gitignore generated vendored Normal file
View File

@@ -0,0 +1,8 @@
# 默认忽略的文件
/shelf/
/workspace.xml
# 基于编辑器的 HTTP 客户端请求
/httpRequests/
# Datasource local storage ignored files
/dataSources/
/dataSources.local.xml

View File

@@ -0,0 +1,10 @@
<component name="InspectionProjectProfileManager">
<profile version="1.0">
<option name="myName" value="Project Default" />
<inspection_tool class="AngularCliAddDependency" enabled="true" level="ERROR" enabled_by_default="true" editorAttributes="ERRORS_ATTRIBUTES" />
<inspection_tool class="AngularInaccessibleComponentMemberInAotMode" enabled="true" level="ERROR" enabled_by_default="true" editorAttributes="ERRORS_ATTRIBUTES" />
<inspection_tool class="AngularInsecureBindingToEvent" enabled="true" level="ERROR" enabled_by_default="true" editorAttributes="ERRORS_ATTRIBUTES" />
<inspection_tool class="AngularInvalidI18nAttribute" enabled="true" level="ERROR" enabled_by_default="true" editorAttributes="ERRORS_ATTRIBUTES" />
<inspection_tool class="AngularNgOptimizedImage" enabled="true" level="ERROR" enabled_by_default="true" editorAttributes="ERRORS_ATTRIBUTES" />
</profile>
</component>

6
.idea/misc.xml generated Normal file
View File

@@ -0,0 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="ProjectRootManager">
<output url="file://$PROJECT_DIR$/out" />
</component>
</project>

8
.idea/modules.xml generated Normal file
View File

@@ -0,0 +1,8 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="ProjectModuleManager">
<modules>
<module fileurl="file://$PROJECT_DIR$/.idea/vue-frame.iml" filepath="$PROJECT_DIR$/.idea/vue-frame.iml" />
</modules>
</component>
</project>

6
.idea/vcs.xml generated Normal file
View File

@@ -0,0 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="VcsDirectoryMappings">
<mapping directory="" vcs="Git" />
</component>
</project>

9
.idea/vue-frame.iml generated Normal file
View File

@@ -0,0 +1,9 @@
<?xml version="1.0" encoding="UTF-8"?>
<module type="JAVA_MODULE" version="4">
<component name="NewModuleRootManager" inherit-compiler-output="true">
<exclude-output />
<content url="file://$MODULE_DIR$" />
<orderEntry type="inheritedJdk" />
<orderEntry type="sourceFolder" forTests="false" />
</component>
</module>

7
components.d.ts vendored
View File

@@ -7,6 +7,13 @@ export {}
declare module 'vue' {
export interface GlobalComponents {
ElAffix: typeof import('element-plus/es')['ElAffix']
ElButton: typeof import('element-plus/es')['ElButton']
ElCarousel: typeof import('element-plus/es')['ElCarousel']
ElCarouselItem: typeof import('element-plus/es')['ElCarouselItem']
ElMenu: typeof import('element-plus/es')['ElMenu']
ElMenuItem: typeof import('element-plus/es')['ElMenuItem']
ElScrollbar: typeof import('element-plus/es')['ElScrollbar']
Foot: typeof import('./src/components/Foot.vue')['default']
Head: typeof import('./src/components/Head.vue')['default']
RouterLink: typeof import('vue-router')['RouterLink']

View File

@@ -1,9 +1,12 @@
<!DOCTYPE html>
<html lang="en">
<html lang="zh-CN">
<head>
<meta charset="UTF-8" />
<link rel="icon" href="/favicon.ico" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<meta
name="viewport"
content="width=device-width,initial-scale=1.0,maximum-scale=1.0,user-scalable=0"
/>
<title>Vite App</title>
</head>
<body>

View File

@@ -12,19 +12,23 @@ import axios from 'axios' //引入 axios库
import qs from 'qs' //引入 node中自带的qs模块数据格式转换
/* 2.全局默认配置 */
let baseURL
let process: any
let process: any = {
env: {
NODE_ENV: 'development'
}
}
// 判断开发环境(一般用于本地代理)
if (process.env.NODE_ENV === 'development') {
// 开发环境
baseURL = 'http://www.liulongbin.top:3006' // 你设置的本地代理请求(跨域代理),下文会详细介绍怎么进行跨域代理
baseURL = 'https://api.vvhan.com/' // 你设置的本地代理请求(跨域代理),下文会详细介绍怎么进行跨域代理
} else {
// 编译环境
if (process.env.type === 'test') {
// 测试环境
baseURL = 'http://www.liulongbin.top:3006'
baseURL = 'https://api.vvhan.com/'
} else {
// 正式环境
baseURL = 'http://www.liulongbin.top:3006'
baseURL = 'https://api.vvhan.com/'
}
}
// 配置axios的属性
@@ -63,6 +67,7 @@ Axios.interceptors.request.use(
return Promise.reject(error)
}
)
Axios.interceptors.response.use(
(res) => {
//请求响应后拦截

View File

@@ -1,47 +1,31 @@
/*
* @Description: {{ByRuin}}
* @Version: 2.0
* @Author: Ruin 🍭
* @Date: 2022-01-25 17:42:57
* @LastEditors: 刘引
* @LastEditTime: 2022-01-25 18:04:29
*/
import Axios from "../api/base-service"; // 导入配置好的axios文件
import Axios from '@/api/base-service' // 导入配置好的axios文件
// 封装axios请求函数并用export导出
export function getInfo(datas: unknown) {
// get请求
const getInfo = (params: unknown) => {
return Axios({
url: "/api.php?key=free&appid=0&msg=鹅鹅鹅",
method: "GET",
url: '/api/horoscope',
method: 'get',
headers: {
"content-type": "application/json",
'Content-Type': 'application/x-www-form-urlencoded' //设置请求头请求格式form
},
data: datas,
});
params
})
}
export function getInfoA(datas: unknown) {
// post请求
const getItem = (data: unknown) => {
return Axios({
url: "/api/getbooks",
method: "get",
url: '/api/getItem',
method: 'post',
headers: {
"Content-Type": "application/x-www-form-urlencoded", //设置请求头请求格式form
'Content-Type': 'application/json' //设置请求头请求格式为json
},
data: datas,
});
data
})
}
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",
});
const HomeApi = {
getInfo,
getItem
}
export default HomeApi

View File

@@ -1,13 +0,0 @@
/*
* @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;

View File

@@ -1,13 +0,0 @@
/*
* @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

View File

@@ -1,11 +1,3 @@
<!--
* @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>
@@ -14,9 +6,33 @@
</div>
</template>
<script setup lang="ts">
import { computed, watch, onUpdated, ref, reactive } from 'vue';
import { computed, watch, onUpdated, ref, reactive, onBeforeMount } from 'vue'
import news from './components/news.vue'
import HomeApi from '@/services/home'
// get请求
const getDataFromApi = async () => {
try {
const res = await HomeApi.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>

View File

@@ -1,12 +1,15 @@
<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>