main.js:
import Vue from 'vue';
import App from './App';
import router from './routes/Route';
Vue.config.productionTip = false;
new Vue({
el: '#app',
render: h => h(App),
router
})
Route.js:
import Vue from "vue";
import VueRouter from "vue-router";
import Routes from "./Routes";
Vue.use(VueRouter);
export default new VueRouter({
mode: 'history',
Routes
});
Routes.js:
import About from '../components/About';
import Work from '../components/Work';
import Contact from '../components/Contact';
export default [
{
path: '/about',
name: 'about',
component: About
}
]
Menu.vue:
<template>
<div class="menu-top">
<router-link class="menu-href-route" to="/about"><span>About</span></router-link>
</div>
</template>
<script>
export default {
name: 'Menu',
}
</script>
Hello.vue:
<template>
<div class="hello">
<router-view></router-view>
</div>
</template>
<script>
import About from './About';
export default {
name: "Hello"
}
</script>
About.vue:
<template>
<div>
About test text
</div>
</template>
<script>
export default {
name: "about"
}
</script>
我在Route.js路由文件中创建并将其导出到main.js。接下来在Routes.js文件中,我创建componentns的路径。在Menu.js文件中是router-link。并且文件Hello.vue具有路由器视图。 About.vue是视图组件。我不知道为什么地址为http://localhost:8080/about
的组件About.vue不能加载到文件Hello.vue中。我重新安装了节点和vue-router,但这无济于事。
答案 0 :(得分:1)
由于js区分大小写,因此请尝试进行此类更改
import Vue from "vue";
import VueRouter from "vue-router";
import Routes from "./Routes";
Vue.use(VueRouter);
export default new VueRouter({
mode: 'history',
routes: Routes
});