我正在尝试使用"https://example.com/some/path"和Vue路由器获取当前路径(类似于Vue3 )。
在使用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 (埃文说过你在这里)。
那么,使用Vue3获取当前路由的首选方法是什么?
发布于 2021-02-01 08:43:05
您可以使用可组合函数useRoute:
import {useRoute} from 'vue-router'
import {computed} from 'vue'
...
setup(){
const route=useRoute();
const path = computed(() =>route.path)
}https://stackoverflow.com/questions/65989489
复制相似问题