vue-router踩坑日记Unknown custom element router-view
今天笔者在研究vue-router的时候踩到了一个小坑,这个坑是这样的

笔者的具体代码如下:
router.js
import Home from '@/components/Home.vue';
import Component1 from '@/components/component1.vue'; const routes = [
{ path: '/component1', name:'component1', component: Component1 },
]
export default routes
main.js
import Vue from 'vue';
import App from './App.vue';
import VueRouter from 'vue-router'; import Routes from '@/router/router.js' Vue.config.productionTip = true;
const router = new VueRouter({
routes: Routes,
mode: "history"
}) new Vue({
render: h => h(App),
router: router
}).$mount('#app');
component1.vue
<template>
<div class="component1">
<h1>{{message}}1</h1>
</div>
</template> <script>
export default {
name: 'componnent1',
data () {
return {
message: "hello vue-router"
};
}
}
</script> <style scoped>
</style>
百度报错原因,发现没有在main.js上面原来是没有手动调用Vue.use(VueRouter)。以前习惯了在文件头部直接引入vue.js和vue-router.js,这种方式下,在vue-router内部会检测window.Vue对象是否存在,如果存在就会自动调用Vue.use()方法,否则需要手动调用Vue.use(VueRouter)来确保路由插件注册到Vue中。在支持AMD环境中,Vue对象并不会暴露到全局window对象中,而是会通过define()形式输出和引入,因此需要手动注册。(具体原因拷贝自博客:https://blog.csdn.net/zhangxuekang/article/details/79738820 。尊重原创,侵删。)
在mian.js上面加入Vue.use(VueRouter)就不会报错了…

转: https://blog.csdn.net/luciferms/article/details/83792402
vue-router踩坑日记Unknown custom element router-view的更多相关文章
- 基于 Laravel 开发 ThinkSNS+ 中前端的抉择(webpack/Vue)踩坑日记【ThinkSNS+研发日记系列】
在上一篇文章< ThinkSNS+基于Laravel master分支,从1到 0,再到0.1>,简单的介绍了 社群系统ThinkSNS+ ,这里分享在开发过程中,前端选择的心理活动. L ...
- 基于 Laravel 开发 ThinkSNS+ 中前端的抉择(webpack/Vue)踩坑日记
在上一篇文章< ThinkSNS+基于Laravel master分支,从1到 0,再到0.1>,简单的介绍了 ThinkSNS+ ,这里分享在开发过程中,前端选择的心理活动. Larav ...
- 【Android】【踩坑日记】RecyclerView获取子View的正确姿势
开发过程中发现RecyclerView.getChildAt(position)为空的情况,但是明明这个position却没有越界. 解决办法:用recycler.getLayoutManager() ...
- 使用vue.js路由踩到的一个坑Unknown custom element
在配合require.js使用vue路由的时候,遇到了路由组件报错: “vue.js:597 [Vue warn]: Unknown custom element: <router-link&g ...
- 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 ...
- (错误记录)Vue: Unknown custom element
错误: vue.js:634 [Vue warn]: Unknown custom element: <ve-pie> - did you register the component c ...
- vue components registration & vue error & Unknown custom element
vue components registration & vue error & Unknown custom element vue.esm.js:629 [Vue warn]: ...
- [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 ...
- 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 ...
随机推荐
- Java 之 线程 —线程通信( 等待唤醒机制)
一.线程间通信 概念:多个线程在处理同一资源,但是处理的动作(线程的任务)却不相同. 例如: 线程 A 用来生成包子的,线程 B 用来吃包子的,包子可以理解为同一资源,线程 A 与线程 B 处理的动作 ...
- kbmmw 中使用带验证的REST 服务
前面介绍的rest 服务,虽然很方便,但是存在任何人都可以访问的安全问题. 今天说一下,如何在kbmmw 中使用带验证的REST 服务? 首先我们在工程中放一个 认证控件TkbmMWAuthoriza ...
- 记录一次Oracle创建DBLink踩到小坑
1.查询当前是否具有创建DBlink的权限: select * from user_sys_privs where privilege like upper('%DATABASE LINK%'); 如 ...
- lua redis接口 (在ubuntu16.04 环境下配置lua-redis开发环境)
目前成功的lua版本是5.1, 根据网络上的资料显示 lua5.1能够支持 lua-socket 安装lua及相关软件: #安装lua5. #安装lua-socketxiangg sudo apt i ...
- 设计模式--Proxy模式
这篇主要介绍代理模式相关内容,主要是一些基本概念普及. 代理模式 1.什么是代理模式? 代理模式(Proxy),为其他对象提供一种代理以控制对这个对象的访问.[DP] 通俗的说就是指客户端并不直接调用 ...
- Diagnostic Viewer 显示空白
MATLAB R2014a仿真出现错误后,查找错误时,Diagnostic Viewer 显示空白.网上查的一种解决方法.我的电脑是Windows7. 1.点击 所有程序>附件>记事本(以 ...
- Beta 冲刺总结
作业要求 这个作业属于哪个课程 软件工程1916-W(福州大学) 这个作业要求在哪里 项目Beta冲刺总结 团队名称 基于云的胜利冲锋队 项目名称 云评:高校学生成绩综合评估及可视化分析平台 这个作业 ...
- 项目Beta冲刺--4/7
项目Beta冲刺--4/7 作业要求 这个作业属于哪个课程 软件工程1916-W(福州大学) 这个作业要求在哪里 项目Beta冲刺 团队名称 基于云的胜利冲锋队 项目名称 云评:高校学生成绩综合评估及 ...
- Brief Introduction to SDK – JRE – JVM – JIT
Brief Introduction to SDK – JRE – JVM – JIT SDK This is complete collection of Java stuff, as it has ...
- NSKeyedArchiver : NSCoder
NSKeyedArchiver : NSCoder @interface NSData : NSObject <NSCopying, NSMutableCopying, NSSecureCodi ...