vuerouter的使用编程式导航和函数式导航

除了使用 创建 a 标签来定义导航链接,我们还可以借助 router 的实例方法,通过编写代码来实现。
router.push(location, onComplete?, onAbort?)
想要导航到不同的 URL,则使用 router.push 方法。这个方法会向 history 栈添加一个新的记录,所以,当用户点击浏览器后退按钮时,则回到之前的 URL。

当你点击 时,这个方法会在内部调用,所以说,点击 等同于调用 router.push(…)。

声明式 编程式
router.push(…)

首先使用vuerouter先要全局注册vuerouter
在vue中全局注册vuerouter
然后再组件中使用
跳转链接
一般用于登录成功使用

 this.$router.push({ path: '/my' })

或者使用router-link

 <li ><router-link  tag="li" to="/my"><img  @click="fun('4')" :src="calImg(4)" alt=""><p>我的</p></router-link></li>

猜你喜欢

转载自blog.csdn.net/mlonly/article/details/88169173