router/index.js
导入Vue和路由插件VueRouter
导入自定义组件

import Vue from 'vue'
import VueRouter from 'vue-router'

const Home = () => import('../home/Home')
const Profile = () => import('../profile/Profile')

1.安装插件
Vue.use(VueRouter)

2.创建路由对象

const routes = [
  {
    path:'',
    redirect:'/home'
  },
  {
    path:'/home',
    component:Home
  },
  {
    path:'/home',
    component:Home
  }
]
const router = new VueRoute({
  routes
})

3.导出路由
export default router

App.vue
1.导入

new Vue({
  el:'#app',
  router,
  render:h => h(App)
})

Hard heart
1 声望0 粉丝

« 上一篇
vue中key的作用
下一篇 »
Js数组去重