Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

请在vue-router3版本中加入useRoute和useRouter钩子函数。 #3889

Closed
qew4 opened this issue Jun 14, 2024 · 2 comments
Closed

请在vue-router3版本中加入useRoute和useRouter钩子函数。 #3889

qew4 opened this issue Jun 14, 2024 · 2 comments

Comments

@qew4
Copy link

qew4 commented Jun 14, 2024

Version

3.6.5

Steps to reproduce

因为vue2.7是支持组合式API的,但是又只支持vue-router3,vue-router3 又没有实现useRoute和useRouter钩子函数。这就导致我们自己实现的钩子函数useRoute和useRouter无法在watch中被监听到变化,主要是useRoute().query的变化。
我们自己封装的钩子如下:
import { getCurrentInstance } from 'vue'
/** this.$route替换方案 /
export function useRoute() {
const { proxy } = getCurrentInstance()
const route = proxy.$route
return route
}
/
* this.$router替换方案 */
export function useRouter() {
const { proxy } = getCurrentInstance()
const router = proxy.$router
return router
}

What is expected?

想要watch能监听到useRoute().query的变化。
在vue-router3中加入useRoute和useRouter钩子函数。

What is actually happening?

watch能不能监听到替代方案useRoute().query的变化。

@posva
Copy link
Member

posva commented Jun 15, 2024

They are already there:

import { useRouter } from 'vue-router/composables'

https://github.com/vuejs/vue-router/blob/dev/src/composables/index.js

@posva posva closed this as completed Jun 15, 2024
@qew4
Copy link
Author

qew4 commented Aug 7, 2024

excellent!
import { useRouter } from 'vue-router/composables' it can be watch and work.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants