[这里是Vue的新手] 我见过很多类似的问题,但是没有答案可以帮助我解决错误。
我正在构建一个小的Vue项目,现在我试图将其分成较小的组件和视图。
我的router.js看起来像这样:
import Vue from 'vue'
import Router from 'vue-router'
import Jobs from './components/Jobs.vue'
import Companies from './components/Companies.vue'
import Events from './components/Events.vue'
Vue.use(Router)
export default new Router ({
routes: [
{
path: '/jobs',
name: 'jobs',
component: 'Jobs'
},
{
path: '/companies',
name: 'companies',
component: 'Companies'
},
{
path: '/events',
name: 'events',
component: 'Events'
}
]
})
其余的,您可以签出此仓库,文件很少https://github.com/anaivanm/vue-tw/ 这个错误使我发疯,我不知道为什么它没有编译。
./src/router.js
Module Error (from ./node_modules/eslint-loader/index.js):
error: 'Jobs' is defined but never used (no-unused-vars) at src/router.js:3:8:
1 | import Vue from 'vue'
2 | import Router from 'vue-router'
> 3 | import Jobs from './components/Jobs.vue'
| ^
4 | import Companies from './components/Companies.vue'
5 | import Events from './components/Events.vue'
6 |
我想念什么?
答案 0 :(得分:0)
component: 'Jobs'
中不需要使用单引号,而您可能想做的是改为使用组件:
...
import Jobs from './components/Jobs.vue'
...
export default new Router ({
routes: [
{
path: '/jobs',
name: 'jobs',
component: Jobs
},
...
请确保您已完全按照其official page中的说明配置了Vue.Router。
这里是一个报价:
// 2. Define some routes
// Each route should map to a component. The "component" can
// either be an actual component constructor created via
// `Vue.extend()`, or just a component options object.
// We'll talk about nested routes later.
const routes = [
{ path: '/foo', component: Foo },
{ path: '/bar', component: Bar }
]