优化 router.query 取值
This commit is contained in:
@@ -10,7 +10,9 @@ import {
|
|||||||
toArray,
|
toArray,
|
||||||
map,
|
map,
|
||||||
debounce,
|
debounce,
|
||||||
nth
|
nth,
|
||||||
|
assign,
|
||||||
|
parse
|
||||||
} from "../utils";
|
} from "../utils";
|
||||||
|
|
||||||
// 路由信息类型
|
// 路由信息类型
|
||||||
@@ -36,11 +38,16 @@ type Events = {
|
|||||||
export class Router {
|
export class Router {
|
||||||
private eventsMap = {} as Events; // 事件存储
|
private eventsMap = {} as Events; // 事件存储
|
||||||
|
|
||||||
// 获取缓存的路由参数
|
// 获取传递的 params 参数
|
||||||
params() {
|
params() {
|
||||||
return (storage.get("router-params") ?? {}) as UTSJSONObject;
|
return (storage.get("router-params") ?? {}) as UTSJSONObject;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 获取传递的 query 参数
|
||||||
|
query() {
|
||||||
|
return this.route()?.query ?? {};
|
||||||
|
}
|
||||||
|
|
||||||
// 获取默认路径,支持 home 和 login
|
// 获取默认路径,支持 home 和 login
|
||||||
defaultPath(name: "home" | "login") {
|
defaultPath(name: "home" | "login") {
|
||||||
const paths = {
|
const paths = {
|
||||||
@@ -82,7 +89,8 @@ export class Router {
|
|||||||
// #endif
|
// #endif
|
||||||
|
|
||||||
// 获取页面 query 参数
|
// 获取页面 query 参数
|
||||||
const query = (get(e, "options") ?? {}) as UTSJSONObject;
|
// @ts-ignore
|
||||||
|
const query = e.options;
|
||||||
|
|
||||||
return {
|
return {
|
||||||
path,
|
path,
|
||||||
|
|||||||
@@ -15,7 +15,7 @@
|
|||||||
<script lang="ts" setup>
|
<script lang="ts" setup>
|
||||||
import { t } from "@/locale";
|
import { t } from "@/locale";
|
||||||
import DemoItem from "../../components/item.uvue";
|
import DemoItem from "../../components/item.uvue";
|
||||||
import { userInfo, useStore } from "@/cool";
|
import { router, userInfo, useStore } from "@/cool";
|
||||||
|
|
||||||
const { user } = useStore();
|
const { user } = useStore();
|
||||||
|
|
||||||
@@ -24,6 +24,11 @@ const props = defineProps({
|
|||||||
type: String
|
type: String
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
onReady(() => {
|
||||||
|
const query = router.query();
|
||||||
|
console.log(query);
|
||||||
|
});
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<style lang="scss" scoped></style>
|
<style lang="scss" scoped></style>
|
||||||
|
|||||||
Reference in New Issue
Block a user