美文网首页
setup 中使用 路由

setup 中使用 路由

作者: 程序猿的小生活 | 来源:发表于2022-11-18 09:18 被阅读0次

1.在setup里边因为不能访问this,所以也没有this.router和this.route。
但是我们可以通过vue-router提供的函数来进行访问router:

useRoute
返回当前路由地址。相当于在模板中使用 route。必须在 setup() 中调用。 useRouter 返回 router 实例。相当于在模板中使用router。必须在 setup() 中调用。

<template>
<div @click="aa()">测试</div>
</template>

<script setup>
    import {useRouter} from'vue-router'
    const router = useRouter()
let aa= ()=>{
        router.push("/about")
    }
</script>

<style>
</style>

相关文章

网友评论

      本文标题:setup 中使用 路由

      本文链接:https://www.haomeiwen.com/subject/hdtpxdtx.html