生成要在vue中使用的API客户端

问题描述 投票:0回答:1

[我已经使用NSwag使用Axios模板来生成Typescript API客户端,以便在vue前端中使用(如果需要,我可以添加生成的客户端以及nswag配置)。

Axios已添加为依赖项:

  "dependencies": {
    "axios": "^0.19.0",
    "core-js": "^2.6.5",
    "vue": "^2.6.10",
    "vue-router": "^3.0.3",
    "vuelidate": "^0.7.4"
  },

目前,我仅尝试导入单个客户端:

import usersClient from "@/api.ts";

[使用npm run serve为前端提供服务时,出现以下错误(由于上述导入):

 ERROR  Failed to compile with 1 errors                                                                         11:51:19
 error  in ./src/api.ts

Module parse failed: Unexpected token (13:12)
You may need an appropriate loader to handle this file type.
|
| export class UsersClient {
>     private instance: AxiosInstance;
|     private baseUrl: string;
|     protected jsonParseReviver: ((key: string, value: any) => any) | undefined = undefined;

 @ ./node_modules/cache-loader/dist/cjs.js??ref--12-0!./node_modules/babel-loader/lib!./node_modules/cache-loader/dist/cjs.js??ref--0-0!./node_modules/vue-loader/lib??vue-loader-options!./src/components/LoginDialogModal.vue?vue&type=script&lang=js& 69:0-35
 @ ./src/components/LoginDialogModal.vue?vue&type=script&lang=js&
 @ ./src/components/LoginDialogModal.vue
 @ ./node_modules/cache-loader/dist/cjs.js??ref--12-0!./node_modules/babel-loader/lib!./node_modules/cache-loader/dist/cjs.js??ref--0-0!./node_modules/vue-loader/lib??vue-loader-options!./src/App.vue?vue&type=script&lang=js&
 @ ./src/App.vue?vue&type=script&lang=js&
 @ ./src/App.vue
 @ ./src/main.js
 @ multi (webpack)-dev-server/client?http://192.168.1.110:8080/sockjs-node (webpack)/hot/dev-server.js ./src/main.js

有人可以把我的建议You may need an appropriate loader to handle this file type.指示给正确的方向吗?

我对Vue并不陌生,也不熟悉整个Web堆栈,因此我可能会错过一些显而易见的东西。

vue.js axios nswag
1个回答
0
投票

问题是该项目尚未完全设置好打字稿。

© www.soinside.com 2019 - 2024. All rights reserved.