Commit dc07bbc0 by 杨灿

updata:接口调取优化

parent f0e7ad3a
import request from './request'; // 请替换成你实际使用的请求库
// 定义一个登录请求的函数
export const login = async (email:string, password:string) => {
try {
const result = await request({
method: 'POST',
url: `/auth/login?login=${email}&password=${password}`,
// 其他请求配置...
});
return result.data; // 返回请求成功时的数据
} catch (error) {
// 处理请求失败的逻辑
console.error('Error fetching data:', error);
throw error; // 将错误继续抛出,以便在组件中处理
}
};
\ No newline at end of file
......@@ -2,19 +2,19 @@
<script setup lang="ts">
import { ref } from 'vue'
import request from '../api/request'
// import request from '../api/request'
import { login } from '../api/login'
const data = ref('')
const fetchData = async () => {
try {
const result = await request<string>({
method: 'POST',
url: '/auth/login?login=shi.jiuyan@163.com&password=654321',
// 其他请求配置...
});
data.value = result.data; // 注意这里的修改
// 调用login函数,并传递登录名和密码
const result = await login('shi.jiuyan@163.com', '654321');
// 处理请求成功的逻辑
console.log('Login successful:', result);
// 这里你可以将数据保存到响应式的Vue数据中,或者进行其他操作
} catch (error) {
// 处理请求失败的逻辑
console.error('Error fetching data:', error);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment