将 TS 文件导入 Vue 文件

And*_*rea 8 typescript vue.js

我制作了一个带有枚举和接口的 ts 文件,我需要在 Vue 组件中使用它们。但是,当我尝试将 ts 文件导入到我的 Vue 组件中时,我收到一条错误,提示找不到该模块。

我的 src/models/Profile.ts 文件如下所示:

export enum Status {
    NONE,
    ACCEPTING,
    NOT_ACCEPTING,
}

export interface Profile {
    status: Status,
    firstName: string,
    lastName: string,
}
Run Code Online (Sandbox Code Playgroud)

我尝试导入上面的 Vue 组件:

import Profile from '@/models/Profile.ts';

@Component({computed: mapGetters(['user'])})
export default class CreateProfile extends Vue {
    ...
}
Run Code Online (Sandbox Code Playgroud)

具体错误:

An import path cannot end with a '.ts' extension. Consider importing '@/models/Profile' instead.
Run Code Online (Sandbox Code Playgroud)

但当我尝试这样做时,我得到:

Cannot find module '@/models/Profile'.
Run Code Online (Sandbox Code Playgroud)

小智 0

试试这个: import type { Profile } from '@/models/Profile.ts';