Vue 路由器错误
Vue Router Error
正在尝试设置 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>' }
这只是他和我一样吗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')
我的 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>
假设你的组件正确,你仍然需要一个小的更新。
当加载vue router作为模块系统时,应用程序应该通过以下方式初始化:
new Vue({
el: '#app',
router,
render: h => h(App)
});
正在尝试设置 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>' }
这只是他和我一样吗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')
我的 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>
假设你的组件正确,你仍然需要一个小的更新。
当加载vue router作为模块系统时,应用程序应该通过以下方式初始化:
new Vue({
el: '#app',
router,
render: h => h(App)
});