vue-router的基本使用

vue-route

1.vue-router安装下载

npm install vue-router --save

2.Vue实例中引入



3.配置router


4.路由跳转

this.$router.push({path:'/my'})  path为跳转路径

this.$router.push({name:'My'}) 用name作为路由跳转

this.$router.push({name:'My',params:{name:'张三'}}) 将要传递的参数放在params(还可通过query)传过去,通过this.$route.params.name获取

this.$router.replace() 此方法不会产生历史记录,push方法都会有历史记录

this.$router.go(num) 向前或向后跳转num个页面,比如this.$router.go(-1) 就是返回上一页

5.获取通过路由传递的参数


最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。