iot-ui-vue/src/utils/hooks/useParams.ts

24 lines
637 B
TypeScript
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

import {useMenuStore} from "store/menu";
import { onBeforeUnmount } from 'vue'
export const useRouterParams = () => {
const params = ref<Record<string, any>>({})
const menu = useMenuStore();
const router = useRouter();
const routeName = router.currentRoute.value.name as string
watchEffect(() => {
params.value = routeName && menu.params[routeName] ? menu.params[routeName] : {}
})
onBeforeUnmount(() => {
if (routeName && menu.params[routeName]) { // 如果当前路由params参数离开页面清除掉
menu.params = {}
}
})
return {
params
}
}