我已经使用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堆栈都不是很精通,所以我可能会错过一些显而易见的内容。
答案 0 :(得分:0)
问题在于该项目尚未完全设置好打字稿。