vue,VueRouter路由使用
文章目录
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)
})
评论
登录后参与技术讨论,分享你的经验与见解。
登录 / 注册暂无评论