vue中 route 路由的用法 + 实现点击跳转
vue中路由的用法:
const routes = [ { path: "/", redirect: '/welcome' }, { path: "/welcome", component: home, children:[ { path: "/welcome" ,component: welcome }, { path: "/form" ,component: form }, ]}, { path: "/login" ,component: login } ] //path: 访问的路径 //redirect: 重定向的路径 //component: 加载的组件 //children:[] 二级路由 //name: 路由的名字
vue中路由实现点击跳转:
<div @click="gotoMenu">按钮</div>
methods: { gotoMenu(){ //指定跳转的地址 this.$router.replace('/menu') //通过push进行跳转 this.$router.push('/menu') //指定跳转的路由的名字下 this.$router.replace({name:'menu'}) //跳转到上一次浏览的页面 this.$router.go(-1) } }, }
posted on 2021-03-15 15:08 cropsecrab 阅读(1480) 评论(0) 收藏 举报
浙公网安备 33010602011771号