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 ...
随机推荐
- Web消息推送框架windows部署实践
一.官方下载地址:https://www.workerman.net/web-sender 二.解压至任意目录下,双击start_for_win.bat,效果如下图: 三.打开Chrome浏览器访问: ...
- Python 集合(Set)、字典(Dictionary)
集合(Set) 集合是无序的,无序也就没有索引,不能进行索引相关的操作.无序,python解释器就不能通过索引(位置)区分集合中的相同元素,所以集合中不能有相同的元素. 集合用大括号{ }表示. 集 ...
- DTC配置
在A和B上配置DTC(控制面板→管理工具→组件服务),配置参数如下: 使防火墙里的3个规则enable
- Ansible入门笔记(3)之Playbook
目录 Ansible-playbook 1.1.什么是playbook? 1.2.playbook的核心组成 1.3.playbook的handlers.notify触发 1.4.playbook的变 ...
- IIS配置伪静态 集成模式 样式丢失
最近将一个老网站迁移到新服务器,因为需要做伪静态配置,在网上找了一些教程跟着配置.结果却出现:按照网上教程配置完后将应用程序池模式改为经典模式,然后验证规则就匹配不了.改成集成模式验证规则能匹配但是网 ...
- linux下apache和tomcat整合
一 Apache与Tomcat比较联系 apache支持静态页,tomcat支持动态的,比如servlet等. 一般使用apache+tomcat的话,apache只是作为一个转发,对jsp的处理是由 ...
- Python装饰器与闭包
闭包是Python装饰器的基础.要理解闭包,先要了解Python中的变量作用域规则. 变量作用域规则 首先,在函数中是能访问全局变量的: >>> a = 'global var' & ...
- 汇编 JMP 详解
汇编 JMP 详解 关键词说明 RVA: 相对虚拟地址(Relative Virtual Address),在内存中相对于PE文件装入地址的偏移位置,是一个相对地址. JMP 的 3 种类型 短跳转( ...
- 使用NB Exploit Kit攻击的APT样本分析——直接看流程图,就是网页挂马,利用java和flash等漏洞来在你主机安装和运行恶意软件
使用NB Exploit Kit攻击的APT样本分析 from:https://cloud.tencent.com/developer/article/1092136 1.起因 近期,安恒工程师在某网 ...
- python应用-工资计算
""" 工资计算 Author:罗万财 Date:2017-6-8 """ salary=float(input('请输入工资:')) in ...