尝试设置Vue路由器。不知道我在做什么错。得到错误
Failed to mount component: template or render function not defined. (found in root instance)
再说一次,我是从React来到Vue的,虽然它们很相似,但是有些小东西却有所不同,而且Vue资源还不多。
我正在使用Webpack模板并使用单个文件组件。我不完全了解的一件事是文档中的这一部分
// 1. Define route components.
// These can be imported from other files
const Foo = { template: '<div>foo</div>' }
const Bar = { template: '<div>bar</div>' }
Run Code Online (Sandbox Code Playgroud)
他和我一样import Foo from 'path/to/component/吗?
无论如何,感谢您的所有帮助!
这是我的main.js档案
import Vue from 'vue'
import App from './App'
import QuizBuilder from '../src/components/QuizBuilder.vue'
import ResourceInfo from '../src/components/ResourceInfo.vue'
import VueRouter from 'vue-router'
Vue.use(VueRouter)
const routes = [
{ path: '/info', component: ResourceInfo },
{ path: '/quiz-builder', component: QuizBuilder }
]
const router = new VueRouter({
routes
})
const app = new Vue({
router
}).$mount('#app')
Run Code Online (Sandbox Code Playgroud)
我index.html看起来像这样
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" integrity="sha384-BVYiiSIFeK1dGmJRAkycuHAHRg32OmUcww7on3RYdg4Va+PmSTsz/K68vbdEjh4u" crossorigin="anonymous">
<title>Digestible</title>
</head>
<body>
<div id="app">
<router-view></router-view>
</div>
<!-- built files will be auto injected -->
</body>
</html>
Run Code Online (Sandbox Code Playgroud)
假设您正确安装了组件,则仍然需要进行少量更新。
将vue路由器加载为模块系统时,应使用以下方式初始化应用程序:
new Vue({
el: '#app',
router,
render: h => h(App)
});
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
1777 次 |
| 最近记录: |