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前端2019面试总结2
1.js继承: 想要继承,就必须要提供个父类(继承谁,提供继承的属性) 组合继承(组合原型链继承和借用构造函数继承)(常用) 重点:结合了两种模式的优点,传参和复用 特点:1.可以继承父类原型上的属性 ...
- Cheat Engine 模糊数值
打开游戏 玩到换枪为止 换枪 发现子弹数量是有限的200 扫描200 这是初次扫描 开两枪 剩余子弹数量194 再次扫描194 得到地址 尝试得到的这两个地址,经验证,第二个是我们想要的地址 重新开始 ...
- pandas 之 特征工程
import numpy as np import pandas as pd So far(到目前为止) in this chapter we've been concerned with rearr ...
- flask启动找不到路由问题
解决方法
- python生成测试报告HTMLTestRunner时报错ValueError: write to closed file的解决办法
使用HTMLTestRunner时出现了以下问题: self.stream.write(output.encode('utf8')) ValueError: write to closed file ...
- Win10上的Docker应用:Docker-compose(容器编排)
阅读目录: Docker应用:Hello World Docker应用:Docker-compose(容器编排) 前言: 昨天完成了Docker入门示例(Docker应用:Hello World),示 ...
- 云打印 对 追光的人 的Beta产品测试报告
云打印 对追光的人的Beta产品测试报告 课程名称:软件工程1916|W(福州大学) 团队名称: 云打印 作业要求: 项目Beta冲刺(团队) 作业目标:作业集合 团队队员 队员学号 队员姓名 个人博 ...
- 2019牛客暑期多校训练营(第九场)B:Quadratic equation (二次剩余求mod意义下二元一次方程)
题意:给定p=1e9+7,A,B. 求一对X,Y,满足(X+Y)%P=A; 且(X*Y)%P=B: 思路:即,X^2-BX+CΞ0; 那么X=[B+-sqrt(B^2-4C)]/2: 全部部分都要 ...
- python 的 lambda使用笔记
无参数匿名函数: f=lambda: none f() 输出:none 带参数匿名函数: 带一个参数: f=lambda x:x+1 f(1) 输出:2 带多个参数: f=lambda a,b,c:a ...
- Python中*args和**kargs如何使用
对于初学者来说,看到*args和**kargs就头大,到底它们有何用处,怎么使用?本文将和大家一起来扒一扒,希望对大家学习python有所帮助. 1.*args 实质就是将函数传入的参数,存储在元组类 ...