RE: RE: Nuxt开发指南
You are viewing a single comment's thread from:

RE: Nuxt开发指南

Words
51
Reading
1 min
9M

useRouter 返回路由器实例,必须在设置函数、插件或路由中间件中调用。
在Vue组件的模板中,你可以使用$router 来访问路由器。

const router = useRouter()

//几个重要参数:  
url: http://localhost:3000/user/userinfo
router.name: 'user-userinfo' 
router.fullPath: '/user/userinfo'
router.path: '/user/userinfo'

//几个重要的方法
router.back()
//$router.back() 返回上一页
router.forward()
router.go()
router.push({ path: "/home" })
router.replace({ hash: "#bio" })
back: 如果可能的话,回溯历史,和router.go(-1)一样。
forward: 如果可能的话,和 router.go(1)一样,在历史上前进。
go: 在历史中向前或向后移动,而不受 router.back() 和 router.forward()中强制执行的等级限制。


//刷新页面
let router = useRouter()
router.go(0)
或者: window.location.reload()
@lemooljiang: useRouter | Ecency