我正在尝试从导入 LoginForm.vue 。/resources / scripts / views / auth / LoginForm 但TypeScript无法识别路径。
我注意到TypeScript无法识别不在'@'或'./ resources / scripts'根目录中的Vue文件。 这意味着在TypeScript无法识别的情况下,我无法将Vue文件放置在子文件夹中。
我尝试过
AuthenticationRouter.ts
AuthenticationRouter.ts是导入到主路由器文件中的模块。
该模块位于'./ resources / scripts / plugins / router / modules / AuthenticationRouter.ts'
此外,它还没有完成,因为如果没有TypeScript的配合,我无法导入视图文件。
// AuthenticationRouter.ts
// ./resources/scripts/plugins/router/modules/AuthenticationRouter.ts
import LoginForm from '@/views/auth/LoginForm'
// IGNORE EVERYTHING BELOW THIS LINE
export default [
{
path: '/auth/login',
component: LoginForm,
children: [
{
path: '',
name: 'people-welcome',
component: Welcome,
},
],
},
];
LoginForm.vue
// LoginForm.vue
// ./resources/scripts/views/auth/LoginForm.vue
<template>
<LoginFormContainer>
</LoginFormContainer>
</template>
<script lang="ts">
import { Component, Vue } from 'vue-property-decorator';
import LoginFormContainer from '@/components/auth/LoginFormContainer';
@Component({
components: { LoginFormContainer }
})
export default class LoginForm extends Vue {
}
</script>
<style scoped>
</style>
tsconfig.json
// tsconfig.json
// ./tsconfig.json
{
"compilerOptions": {
"target": "es5",
"module": "es2015",
"strict": true,
"jsx": "preserve",
"importHelpers": true,
"moduleResolution": "node",
"skipLibCheck": true,
"esModuleInterop": true,
"sourceMap": true,
"allowSyntheticDefaultImports": true,
"baseUrl": ".",
"emitDecoratorMetadata": true,
"experimentalDecorators": true,
"rootDir": "./resources/scripts/",
"paths": {
"@/*": [
"./resources/scripts/*"
]
},
"typeRoots": [
"node_modules/@types",
"./node_modules/vuetify/types"
],
"lib": [
"esnext",
"dom",
"dom.iterable",
"scripthost"
]
},
"include": [
"./resources/scripts/**/*",
"./resources/scripts/**/*.ts",
"./resources/scripts/**/*.vue",
"./resources/scripts/**/*.tsx",
],
"exclude": [
"/node_modules/"
]
}
vue-shim.d.ts
// vue-shim.d.ts
// ./resources/scripts/vue-shim.d.ts
// I have no idea how this code works, but I found it on the internet
// For some odd reason, TypeScript wasn't able to locate *.vue files such as '@/App.vue' in the index.ts file
// So I found this on Stackoverflow https://stackoverflow.com/questions/42002394/importing-vue-components-in-typescript-file
// and it works for now
declare module "*.vue" {
import Vue from 'vue'
export default Vue
}
答案 0 :(得分:0)
我太傻了,还活着。
事实证明,在导入时,TypeScript将不会在路径中未添加“ .vue”扩展名的情况下识别Vue文件。
我将需要找到一种方法让TypeScript识别不带扩展名的Vue文件。
agggghhhhhhhh