在配合require.js使用vue路由的时候,遇到了路由组件报错:

“vue.js:597 [Vue warn]: Unknown custom element: <router-link> - did you register the component correctly? For recursive components, make sure to provide the "name" option.”

vue.js的功能是好的,vue-route.js没有起作用,这是怎么回事?明明文件也被加载进来了呀。

如果做如下修改就可以了,在router.js中增加

Vue.use(VueRouter) 就可以避免报这个错误
import Vue from 'vue'
import VueRouter from 'vue-router' import HomeContainer from './components/lib/HomeContainer.vue'
import MemberContainer from './components/lib/MemberContainer.vue'
import ShopcarContainer from './components/lib/ShopcarContainer.vue'
import SearchContainer from './components/lib/SearchContainer.vue' Vue.use(VueRouter) var router = new VueRouter({
routes:[
{path:'/home', component: HomeContainer},
{path:'/member', component: MemberContainer},
{path:'/shopcar', component: ShopcarContainer},
{path:'/search', component: SearchContainer}
],
linkActiveClass:'mui-active'
}) export default router

不过这不是和main.js中加载重复了嘛?不知道是架构问题还是工具问题。目前暂时是这个解决方案:

main.js

// The Vue build version to load with the `import` command
// (runtime-only or standalone) has been set in webpack.base.conf with an alias.
import Vue from 'vue'
import App from './App'
import './lib/css/mui.min.css'
import './lib/css/icons-extra.css'
import 'mint-ui/lib/style.css'
import { Header } from 'mint-ui'; import router from './router' Vue.config.productionTip = false Vue.component(Header.name, Header); /* eslint-disable no-new */
new Vue({
render: h => h(App),
router
}).$mount('#app');

其中APP.vue

<template>
<div class="app-container">
<mt-header fixed title="固定在顶部"></mt-header> <router-view></router-view> <nav class="mui-bar mui-bar-tab">
<router-link class="mui-tab-item" to="/home">
<span class="mui-icon mui-icon-home"></span>
<span class="mui-tab-label">首页</span>
</router-link>
<router-link class="mui-tab-item" to="/member">
<span class="mui-icon mui-icon-contact"></span>
<span class="mui-tab-label">会员</span>
</router-link>
<router-link class="mui-tab-item" to="/shopcar">
<span class="mui-icon mui-icon-extra mui-icon-extra-cart"><span class="mui-badge">0</span></span>
<span class="mui-tab-label">购物车</span>
</router-link>
<router-link class="mui-tab-item" to="/search">
<span class="mui-icon mui-icon-search"></span>
<span class="mui-tab-label">搜索</span>
</router-link>
</nav>
</div>
</template> <script> </script> <style scoped>
.app-container{
padding-top: 40px;
}
</style>

使用vue.js路由踩到的一个坑Unknown custom element的更多相关文章

  1. Vue组件化应用构建 官网例子 Unknown custom element: <todo-item>

     [博客园cnblogs笔者m-yb原创,转载请加本文博客链接,笔者github: https://github.com/mayangbo666,公众号aandb7,QQ群927113708] htt ...

  2. Vue.js 入门:从零开始做一个极简 To-Do 应用

    Vue.js 入门:从零开始做一个极简 To-Do 应用 写作时间:2019-12-10版本信息:Vue.js 2.6.10官网文档:https://cn.vuejs.org/ 前言  学习 Vue ...

  3. (错误记录)Vue: Unknown custom element

    错误: vue.js:634 [Vue warn]: Unknown custom element: <ve-pie> - did you register the component c ...

  4. vue报错[Vue warn]: Unknown custom element: <router-Link> - did you register the component correctly? For recursive components, make sure to provide the "name" option.

    vue浏览器报错,如下 vue.runtime.esm.js?2b0e:619 [Vue warn]: Unknown custom element: <router-Link> - di ...

  5. vue components registration & vue error & Unknown custom element

    vue components registration & vue error & Unknown custom element vue.esm.js:629 [Vue warn]: ...

  6. Vue报错之" [Vue warn]: Unknown custom element: <wzwzihello> - did you register the component correctly? For recursive components, make sure to provide the "name" option."

    一.报错截图 [Vue warn]: Unknown custom element: <wzwzihello> - did you register the component corre ...

  7. [Vue warn]: Unknown custom element: <sapn> - did you register the component correctly? For recursive components, make sure to provide the "name" option. found in ---> <Evaluate> at src/views/index/

    关于vue报错: [Vue warn]: Unknown custom element: <sapn> - did you register the component correctly ...

  8. vue.js路由参数简单实例讲解------简单易懂

    vue中,我们构建单页面应用时候,一定必不可少用到vue-router vue-router 就是我们的路由,这个由vue官方提供的插件 首先在我们项目中安装vue-router路由依赖 第一种,我们 ...

  9. Vue.js路由

    有时候,我们在用vue的时候会有这样的需求,比如一个管理系统,点了左边的菜单栏,右边跳转到一个新的页面中,而且刷新的时候还会停留在原来打开的页面. 又或者,一个页面中几个不同的画面来回点击切换,这两种 ...

随机推荐

  1. jqgrid 表格中筛选条件的多选下拉,树形下拉 ;文本框清除插件;高级查询多条件动态筛选插件[自主开发]

    /** * @@desc 文本框清除按钮,如果isAutoWrap为false当前文本框父级必须是relative定位,boostrap参考input-group * @@author Bear.Ti ...

  2. kotlin 插件更新到 1.2.41 程序出错 Please use kotlin-stdlib-jdk7 instead

    buildscript { ext.kotlin_version = '1.2.41' repositories { google() jcenter() } dependencies { class ...

  3. kafka 数据存储结构+原理+基本操作命令

    数据存储结构: Kafka中的Message是以topic为基本单位组织的,不同的topic之间是相互独立的.每个topic又可以分成几个不同的partition(每个topic有几个partitio ...

  4. canvas抛物线运动轨迹

    本来是想做一个贝塞尔曲线运动轨迹的 公式太复杂了,懒得算,公式在最后 我先画了一个抛物线,我确定了两个点,起点(0,0),终点(200,200) 用坐标系可算出方程 y=-0.005x^2 现在找出终 ...

  5. java中关于重载与重写的区别

    1.重载 允许多个同名但是形式参数个数或参数类型不同的方法存在同一个类中,在调用时根据形式参数列表来调用对应的方法. 2.判断 (1):方法名必须相同. (2):形式参数个数不同或者参数类型不同(满足 ...

  6. linux下设置php执行命令

    第一种方法: 打开用户根目录下的: vi ~/.bash_profile # .bash_profile # Get the aliases and functions if [ -f ~/.bash ...

  7. 微信小程序 --- 表单输入验证(手机号、邮箱验证、输入非空)

    js代码 Page({                   /**    * 页面的初始数据    */         data: {         indicatorDots: false,   ...

  8. 查找mac下腾讯视频下载地址

    mac 腾讯视频下载的视频是不可见的,也许是因为版权原因吧.使用以下方法可以在文件中找到缓存的视频(不过都是被断开的很多短视频). 在terminal输入: cd Library/Containers ...

  9. mvc返回多个结果集,返回多个视图

    System.Web.Mvc.ViewPage<dynamic> public ActionResult Index()     {             IDictionary< ...

  10. phpstorm在项目中查找某个字符串

    如果项目过大,想在整个项目中找某个字符串,又不知道该字符串所在文件的路径,这时候就可以使用全局搜索了,ctrl+shift+F.在mac下,快捷键是command+shift+F: