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)
    }
  },
}

 


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM