我正在尝试"https://example.com/some/path"
使用 Vue3 和 Vue-router 获取当前路径(类似于 )。
之前,在使用 Vue2 时,我可以使用以下方法获取当前路线:
// works with vue 2.x with composition-api, but not with vue 3.x
setup(_, ctx) {
const path = computed(() => ctx.root.$route.path)
但在 Vue3 中无法使用ctx.root
(如 Evan You 所述)。
那么用 Vue3 获取当前路由的首选方法是什么?