我有一个基于TypeScript的Vue.js项目,使用Visual Studio 2017作为我的IDE。
这是“ router / index.js”文件:
import Vue from 'vue'
import Router from 'vue-router'
import Home from '@/components/Home'
import TimeSheet from '@/components/TimeSheet'
Vue.use(Router)
export default new Router({
routes: [
{
path: '/',
redirect: {
name: "Home"
}
},
{
path: '/home',
name: 'Home',
component: Home
},
{
path: '/timesheet',
name: 'TimeSheet',
component: TimeSheet
}
]
})
这是我的“ main.ts”文件的内容:
import Vue from 'vue';
import App from './App.vue';
Vue.config.productionTip = true;
import router from './router'
new Vue({
render: h => h(App),
router
}).$mount('#app')
在这一行:
import router from './router'
我得到:
vue.js找不到模块'./router'的声明文件
我看到很多关于此错误的线程,但是到目前为止,没有一个提供解决方案。这是该项目的布局方式:
编辑:
tsconfig.json的内容
{
"compilerOptions": {
"noEmit": true,
"target": "es5",
"module": "esnext",
"strict": true,
"jsx": "preserve",
"moduleResolution": "node",
"experimentalDecorators": true,
"emitDecoratorMetadata": true,
"allowSyntheticDefaultImports": true,
"sourceMap": true,
"baseUrl": ".",
"types": [
"node"
],
"paths": {
"@/*": [
"src/*"
]
}
},
"include": [
"src/**/*.ts",
"src/**/*.tsx",
"src/**/*.vue",
"tests/**/*.ts",
"tests/**/*.tsx"
],
"exclude": [
"node_modules"
]
}
答案 0 :(得分:0)
我将文件router/index.js
更改为index.ts
,然后将文件的内容从...更改了。
import Vue from 'vue'
import Router from 'vue-router'
import Home from '@/components/Home'
import TimeSheet from '@/components/TimeSheet'
Vue.use(Router)
export default new Router({
routes: [
{
path: '/',
redirect: {
name: "Home"
}
},
{
path: '/home',
name: 'Home',
component: Home
},
{
path: '/timesheet',
name: 'TimeSheet',
component: TimeSheet
}
]
})
到...
import Vue from 'vue'
import Router from 'vue-router'
import Home from '@/components/Home.vue'
import TimeSheet from '@/components/TimeSheet.vue'
Vue.use(Router)
export default new Router({
routes: [
{
path: '/',
redirect: {
name: "Home"
}
},
{
path: '/home',
name: 'Home',
component: Home
},
{
path: '/timesheet',
name: 'TimeSheet',
component: TimeSheet
}
]
})
答案 1 :(得分:0)
有用