【发布时间】:2019-02-27 14:52:40
【问题描述】:
我是 VueJs 的新手。我正在尝试使用 VueJs 开发主题,我遇到了 router 的问题,“组件未显示”。这是我的代码
Pagea.vue
<template>
<div>
<h1>Hello This is a test</h1>
</div>
</template>
<script>
export default {
name : "Pagea"
}
</script>
App.vue
<template>
<div id="app">
<router-link to="/">Go to Foo</router-link>
<router-link to="/Pagea">Go to Bar</router-link>
<router-view></router-view>
</div>
</template>
<script>
export default {
name: 'app',
components: {
Header,
Footer
}
}
</script>
main.js
import Vue from 'vue';
import App from './App.vue';
import VueRouter from 'vue-router';
import 'bootstrap/dist/css/bootstrap.css';
import 'bootstrap-vue/dist/bootstrap-vue.css';
Vue.use(BootstrapVue);
Vue.use(VueRouter);
Vue.config.productionTip = false;
//Router
import Pagea from './components/Pagea.vue';
const routers = [
{
path: '/pagea',
name : 'Pagea',
component : Pagea
}
];
const router = new VueRouter({
routers,
mode : 'history'
});
new Vue({
router,
render: h => h(App)
}).$mount('#app')
没有控制台错误,但仍有结果。我不知道为什么组件或数据不只显示空白页面。请任何人都可以告诉我我错过了什么。作为我早期的豪宅,我是新的,还在学习。谢谢。
【问题讨论】:
-
在 const
router声明中使用routes: routers。或者,要以当前方式使用它,您应该将 constrouters重命名为routes -
谢谢。它解决了。
标签: javascript vue.js