vue3的setup中怎么使用路由
import {onMounted, getCurrentInstance } from "vue";
export default {
setup() {
const { ctx } = getCurrentInstance();
function back(){
console.log(ctx.$root.$route) //获取路由对象信息
ctx.$router.back();
}
return {
back
}
}
}
获取路由对象路由元信息比原来麻烦了,加了个root,大家如果有更好办法,麻烦告知。

本文介绍了在Vue3的setup函数中如何使用路由的方法。通过使用getCurrentInstance获取当前实例上下文,进而通过$router.back()实现页面回退。此外,还展示了如何通过ctx.$root.$route获取路由对象信息。

5万+

被折叠的 条评论
为什么被折叠?



