youlaitech / vue3-element-admin

🔥基于 vue3 + vite5 + typescript + element-plus 构建的后台管理前端模板(配套后端源码),vue-element-admin 的 vue3 版本。
https://vue3.youlai.tech
MIT License
1.43k stars 376 forks source link

mock数据模拟时似乎无法拦截url? #158

Closed Allennnn2022 closed 3 months ago

Allennnn2022 commented 3 months ago

mock仿照users写的:

{
    url: "users/TaskShow",
    method: ["GET"],
    body: {
      code: "00000",
      data: [
        { taskname: "Task1", taskstate: "running" },
        { taskname: "Task2", taskstate: "starting" },
      ],
      msg: "一切ok",
    },
  },

请求函数:

import request from "@/utils/request";
//import SERVER_URL from "@/App.vue";
const USER_BASE_URL = "/api/v1/users";
export function gettasklist(query: object) {
  return request<any, Tasklist[]>({
    //url: `${SERVER_URL}/user`,
    url: `${USER_BASE_URL}/TaskShow`,
    method: "get",
    params: query,
  });
}
export interface Tasklist {
  // 任务名称
  taskname?: string;
  // 任务状态
  taskstate?: string;
}

相应包如下:{"code":"B0001","data":null,"msg":"Request method 'GET' is not supported"}

Allennnn2022 commented 3 months ago

求解惑是不是哪里写的有问题

diamont1001 commented 3 months ago

url: `${SERVER_URL}/user/TaskShow

Allennnn2022 commented 3 months ago

那个注释掉了,下面一行才是实际的url

diamont1001 commented 3 months ago

image

把这个打开,然后自己在 Devtools 里看调试信息吧!

然后看看下面这个:

image
Allennnn2022 commented 3 months ago

感谢,原来是没用本地mock