1.在src目录下新建 router目录 创建index.js
2.index.js中的内容
import Vue from 'vue'
import Router from 'vue-router'
//路由懒加载
const home = () => import('@/components/home')
const details = () => import('@/components/details')
Vue.use(Router);
const routes = [
{
path:'',
redirect:'/home'
},
{
path:'/home',
component:home
},
{
path:'/details',
component:details
},
]
const router = new Router({
routes,
mode:'history'
})
export default router
3.在main.js中引入
```javascript
import Vue from 'vue'
import App from './App.vue'
import store from './vuex/index'
import router from './router/index'
Vue.config.productionTip = false
new Vue({
router,
store,
render: h => h(App),
}).$mount('#app')
最后
以上就是合适绿草最近收集整理的关于vue-router的简单封装的全部内容,更多相关vue-router内容请搜索靠谱客的其他文章。
本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
发表评论 取消回复