安装vue-router
npm i vue-router -S
src下建router文件夹,下面建index.js
index.js内容
import Vue from 'vue'
import Router from 'vue-router'
import Home from '@/views/Home'
Vue.use(Router)
const routes = [
{
path:'/',
component: Home
},{
path:'/list',
component: () => import('@/views/List')
}
]
export default new Router({
mode: 'hash',
routes
})
app.vue中通过router-view进行路由部分页面展示
<div id="app">
<router-view></router-view>
</div>
main.js中的部分
import router from './router/index'
new Vue({
render: h => h(App),
router
}).$mount('#app')
网友评论