未知定制元素:<router-link>在VueJS
Unknown custom element: <router-link> in VueJS
我尝试将导航逻辑提取到子组件中,其结构如下:
App.vue -- Header.vue --- Navigation.vue
我试图在导航中使用属性。但是收到以下错误:
Unknown custom element: <router-link> - did you register the component correctly? For recursive components, make sure to provide the "name" option.
这是我的应用程序到目前为止,非常简单和基本。
main.js
require('bootstrap-sass/assets/stylesheets/_bootstrap.scss')
// require('bootstrap-sass/assets/javascripts/bootstrap.js')
require('./assets/sass/app.scss')
import Vue from 'vue'
import VueRouter from 'vue-router'
import VueMoment from 'vue-moment'
import VueResource from 'vue-resource'
import { configRouter } from './routes'
import App from './App'
// Debug mode
Vue.config.debug = true
// Devtools enabled
Vue.config.devtools = true
// Silence logs and warnings
Vue.config.silent = false
// install router
Vue.use(VueRouter)
// install vue-moment filter
Vue.use(VueMoment)
// install resource
Vue.use(VueResource)
// create router
var router = new VueRouter({
history: true,
saveScrollPosition: true
})
// configure router
configRouter(router)
/* eslint-disable no-new */
// new Vue({
// el: 'body',
// components: { App, router }
// })
router.start(App, '#app')
App.vue
<template>
<div>
<site-header></site-header>
<router-view></router-view>
</div>
</template>
<script>
import SiteHeader from './components/Header'
export default {
components: {
SiteHeader
}
}
</script>
Header.vue
<template>
<header class="masthead container-fluid">
<div class="row">
<!-- Branding -->
<div class="col-md-3"> </div>
<!-- / Branding -->
<!-- Primary Navigation -->
<navigation></navigation>
<!-- / Primary Navigation -->
<!-- Actions -->
<div class="col-md-3"> </div>
<!-- / Actions -->
</div>
</header>
</template>
<script>
import Navigation from './Navigation'
export default {
components: {
Navigation
},
data () {
return {
msg: 'Hello World!'
}
}
}
</script>
Navigation.vue
<template>
<div class="col-md-6">
<ul class="primary-navigation list-inline list-unstyled">
<li> <router-link to="/about">About</router-link> </li>
<li> TEST </li>
<li> TEST </li>
<li> TEST </li>
</ul>
</div>
</template>
<script>
import VueRouter from 'vue-router'
export default { components: { VueRouter } }
</script>
我做错了什么?
版本号:vue 1.0.28 &vue-router 0.7.13
From vue-router
docs: http://router.vuejs.org/en/essentials/getting-started.html
// 3. Create the router instance and pass the `routes` option
// You can pass in additional options here, but let's
// keep it simple for now.
const router = new VueRouter({
routes // short for routes: routes
})
我相信路由需要在创建router实例时被传递。我真的不知道你的configRouter(router)
做什么,但你可以保持简单,直到它开始工作。然后,你就可以开始模块化你的组件和配置了。
另外,我不确定router.start
,它在我能找到的文档中没有指定任何地方。路由器文档推荐用这个简单的方法来创建应用的根实例:
// 4. Create and mount the root instance.
// Make sure to inject the router with the router option to make the
// whole app router-aware.
const app = new Vue({
router
}).$mount('#app')
可能你的应用程序还没有路由器感知,正如上面的评论所提到的(来自文档,不是来自我!)这可能是获得router-link
错误的原因。您可以尝试文档中推荐的更简单的方法吗?
相关文章:
- 引导程序:在导航栏中,显示悬停在单个位置的基于Li Link的不同内容
- 混合 ui-sref 和 $state.go 在 Angular ui-router 中进行状态转换
- this.router在AngularJS 2中未定义
- Meteor Router数据函数被调用两次
- 如何使用dropzone&vueJs
- 如何在router.get()方法中传递url作为参数
- renderReact/Rect Router+Node/Express.js的服务器端/同构渲染中未定义renderP
- 在vuejs中呈现具有重复值的数组
- 骨干's Router.execute(callback,args,name)方法获取未定义的名称
- LINK rel=子资源用于什么
- 如何在 React-router 中手动调用 Link
- 是 var { route, redirect, routeHandler, Link } = router;在 Jav
- VueJS和vue-router:使用v-link时,视图数据不会更新
- React Router Link中触发链接的Material-UI组件
- React router Link; activeClassName not working
- React Router Required context ' Router '没有在' Link '中指定
- Angular 2:动态生成链接的Active Router link和routerLinkActiveOptions
- vuejs router - Require没有定义
- 从 Vue 中的 V-Link 传递道具.js使用 Vue-router
- 如何组合ReactJs的Router Link和material-ui组件(比如按钮)