src目录下创建router.js
import Vue from "vue";
import VueRouter from "vue-router";
import ExaminationList from "@/components/examination/ExaminationList";
import Home from "@/components/Home";
// 要告诉 vue 使用 vueRouter
Vue.use(VueRouter);
const routes = [
{
path: '/',
component: Home
},
{
path: '/list',
component: ExaminationList
}
]
var router = new VueRouter({
mode: 'history',//改为history模式,去除url里的#
routes
})
export default router;
App.vue
<template>
<div id="app">
<router-view ></router-view>
</div>
</template>
<script>
export default {
name: 'App',
components: {
},
data:()=>{
return {
}
}
}
</script>
<style>
#app {
font-family: Avenir, Helvetica, Arial, sans-serif;
-webkit-font-smoothing: antialiased;
-moz-osx-font-smoothing: grayscale;
text-align: center;
color: #2c3e50;
margin-top: 60px;
}
</style>
main.js
引入router
import Vue from 'vue'
import App from './App.vue'
Vue.config.productionTip = false
import router from "@/router";
new Vue({
router,
render: h => h(App)
}).$mount('#app')