vue-router的使用方式

橙三吉。 提交于 2019-12-02 09:14:45

step1:下载安装

npm i vue-router -S

step2:main.js中引入

import VueRouter from 'vue-router'

step3:安装插件

Vue.use(VueRouter)

step4:创建路由对象并配置路由规则

let router = new VueRouter({
  routes: [{
    path: '/home', component: Home
  },{
    path: '/error', component: Error
  },{
    path: '/user', component: User
  },,{
    path: '*', redirect: '/home'
  }]
})

step5:将路由对象传递给Vue实例

step6:在app.vue中预留路由位置

step7:封装编程式导航的插件并注册至Vue

https://blog.csdn.net/weixin_40825228/article/details/102490947
step8:使用

this.pop()
this.push(/home)
this.repalce(/error)

 

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!