vue3获取当前路由地址
作者:忞翛 时间:2024-05-09 15:13:36
正解
使用useRouter
:
// router的 path: "/user/:uid"
<template>
<div>user</div>
<p>uid: {{ uid }}</p>
</template>
<script lang="ts">
import { defineComponent } from "vue";
import { useRouter } from "vue-router";
export default defineComponent({
name: "User",
setup() {
const router = useRouter();
const uid = router.currentRoute.value.params.uid;
return {
// 返回的数据
uid,
};
},
});
</script>
解释一下
useRouter()
返回的是object
, 类似于vue2的this.$router
而router.currentRoute
是RefImpl
对象, 即我们使用ref
返回的对象, 通过.value
可以访问到当前的路由, 类似于vue的this.$route
使用console.log
打印出来看看:
来源:https://www.cnblogs.com/lczmx/p/15709172.html
标签:vue3,获取,路由
![](/images/zang.png)
![](/images/jiucuo.png)
猜你喜欢
Python3 MySQL 数据库连接的使用示例
2024-01-21 18:15:40
Python开发常用的一些开源Package分享
2022-12-10 22:00:11
Transact_SQL小手册,适合初学者
2008-08-25 19:40:00
怎样管理好css样式
2008-10-12 12:12:00
8种Python异常检测算法总结
2021-02-26 20:30:35
![](https://img.aspxhome.com/file/2023/6/121526_0s.png)
asp如何验证IP地址?
2010-06-10 18:37:00
python 使用 requests 模块发送http请求 的方法
2021-06-02 17:29:19
基于Jquery+Ajax+Json的高效分页实现代码
2024-05-21 10:12:19
![](https://img.aspxhome.com/file/2023/1/126151_0s.jpg)
python中Event实现线程间同步介绍
2023-08-18 07:07:08
![](https://img.aspxhome.com/file/2023/9/76789_0s.png)
Python logging模块原理解析及应用
2022-04-08 11:14:32
使用Django搭建web服务器的例子(最最正确的方式)
2021-10-23 12:39:11
![](https://img.aspxhome.com/file/2023/9/90859_0s.jpg)
python 教程之blinker 信号库
2023-11-23 10:15:51
PHP实现阿里大鱼短信验证的实例代码
2024-05-11 09:52:20
![](https://img.aspxhome.com/file/2023/0/125830_0s.png)
JavaScript中String.prototype用法实例
2024-04-22 22:18:12
python SVD压缩图像的实现代码
2023-04-18 18:23:30
![](https://img.aspxhome.com/file/2023/6/86496_0s.jpg)
Python批量生成字幕图片的方法详解
2023-11-03 05:03:15
![](https://img.aspxhome.com/file/2023/5/101705_0s.png)
SQLServer2005 没有日志文件(*.ldf) 只有数据文件(*.mdf) 恢复数据库的方法
2024-01-24 00:15:37
深入学习Golang并发编程必备利器之sync.Cond类型
2024-05-09 14:58:34
ASP长文章分页代码实例
2007-10-02 17:04:00
程序员的八种境界,你在哪一境?
2022-07-19 11:22:19
![](https://img.aspxhome.com/file/2023/8/112068_0s.jpg)