requirejs及vue的使用
//index.html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Title</title>
<script async type="text/javascript" data-main="script/main" src="//cdn.bootcss.com/require.js/2.3.3/require.js"></script>
</head>
<body>
<div id="app">
<router-link to="/foo">Go to Foo</router-link>
<router-view></router-view>
</div>
</body>
</html>
//main.js
require.config(
{
paths: {
'vue': '//cdn.bootcss.com/vue/2.3.4/vue',
'vueRouter': '//cdn.bootcss.com/vue-router/2.7.0/vue-router'
}
}
);
require(['vue', 'vueRouter'], function (Vue, Router) {
const Foo = { template: '<div>foo</div>' }
const routes = [
{ path: '/foo', component: Foo }
];
const router = new Router({
routes: routes // (缩写)相当于 routes: routes
});
new Vue({
el: "#app",
router: router
});
});
浏览器报错
vue.js:440 [Vue warn]: Unknown custom element: <router-link> - did you register the component correctly? For recursive components, make sure to provide the "name" option.
(found in <Root>)
[Vue warn]: Unknown custom element: <router-view> - did you register the component correctly? For recursive components, make sure to provide the "name" option.
(found in <Root>)
vue-router,请问是不是写法不对,谢谢
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
Vue.use(VueRouter)
在 new vue之前加上
Vue.use(Router)