Skip to content

Commit ae02573

Browse files
committed
feat: using Vue 3.5's new "Reactive Props Destructure"
1 parent a488b4d commit ae02573

File tree

5 files changed

+24
-32
lines changed

5 files changed

+24
-32
lines changed

.vscode/settings.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,9 @@
22
// Use workspace TypeScript version
33
"typescript.tsdk": "node_modules/typescript/lib",
44

5+
// Show inlay hints for destructured props
6+
"vue.inlayHints.destructuredProps": true,
7+
58
// Disable the default formatter, use eslint instead
69
"prettier.enable": false,
710
"editor.formatOnSave": false,

src/common/components/Screenfull/index.vue

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -12,12 +12,7 @@ interface Props {
1212
content?: boolean
1313
}
1414
15-
const props = withDefaults(defineProps<Props>(), {
16-
element: "html",
17-
openTips: "全屏",
18-
exitTips: "退出全屏",
19-
content: false
20-
})
15+
const { element = "html", openTips = "全屏", exitTips = "退出全屏", content = false } = defineProps<Props>()
2116
2217
const CONTENT_LARGE = "content-large"
2318
@@ -28,11 +23,11 @@ const classList = document.body.classList
2823
// #region 全屏
2924
const isEnabled = screenfull.isEnabled
3025
const isFullscreen = ref<boolean>(false)
31-
const fullscreenTips = computed(() => (isFullscreen.value ? props.exitTips : props.openTips))
26+
const fullscreenTips = computed(() => (isFullscreen.value ? exitTips : openTips))
3227
const fullscreenSvgName = computed(() => (isFullscreen.value ? "fullscreen-exit" : "fullscreen"))
3328
3429
function handleFullscreenClick() {
35-
const dom = document.querySelector(props.element) || undefined
30+
const dom = document.querySelector(element) || undefined
3631
isEnabled ? screenfull.toggle(dom) : ElMessage.warning("您的浏览器无法工作")
3732
}
3833
@@ -79,7 +74,7 @@ function handleContentFullClick() {
7974
<template>
8075
<div>
8176
<!-- 全屏 -->
82-
<el-tooltip v-if="!props.content" effect="dark" :content="fullscreenTips" placement="bottom">
77+
<el-tooltip v-if="!content" effect="dark" :content="fullscreenTips" placement="bottom">
8378
<SvgIcon :name="fullscreenSvgName" @click="handleFullscreenClick" class="svg-icon" />
8479
</el-tooltip>
8580
<!-- 内容区 -->

src/layouts/components/Hamburger/index.vue

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,7 @@ interface Props {
55
isActive?: boolean
66
}
77
8-
const props = withDefaults(defineProps<Props>(), {
9-
isActive: false
10-
})
8+
const { isActive = false } = defineProps<Props>()
119
1210
const emit = defineEmits<{
1311
toggleClick: []
@@ -21,7 +19,7 @@ function toggleClick() {
2119
<template>
2220
<div @click="toggleClick">
2321
<el-icon :size="20" class="icon">
24-
<Fold v-if="props.isActive" />
22+
<Fold v-if="isActive" />
2523
<Expand v-else />
2624
</el-icon>
2725
</div>

src/layouts/components/Logo/index.vue

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,17 +8,15 @@ interface Props {
88
collapse?: boolean
99
}
1010
11-
const props = withDefaults(defineProps<Props>(), {
12-
collapse: true
13-
})
11+
const { collapse = true } = defineProps<Props>()
1412
1513
const { isLeft, isTop } = useLayoutMode()
1614
</script>
1715

1816
<template>
19-
<div class="layout-logo-container" :class="{ 'collapse': props.collapse, 'layout-mode-top': isTop }">
17+
<div class="layout-logo-container" :class="{ 'collapse': collapse, 'layout-mode-top': isTop }">
2018
<transition name="layout-logo-fade">
21-
<router-link v-if="props.collapse" key="collapse" to="/">
19+
<router-link v-if="collapse" key="collapse" to="/">
2220
<img :src="logo" class="layout-logo">
2321
</router-link>
2422
<router-link v-else key="expand" to="/">

src/layouts/components/Sidebar/Item.vue

Lines changed: 12 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -9,15 +9,13 @@ interface Props {
99
basePath?: string
1010
}
1111
12-
const props = withDefaults(defineProps<Props>(), {
13-
basePath: ""
14-
})
12+
const { item, basePath = "" } = defineProps<Props>()
1513
1614
/** 是否始终显示根菜单 */
17-
const alwaysShowRootMenu = computed(() => props.item.meta?.alwaysShow)
15+
const alwaysShowRootMenu = computed(() => item.meta?.alwaysShow)
1816
1917
/** 显示的子菜单 */
20-
const showingChildren = computed(() => props.item.children?.filter(child => !child.meta?.hidden) ?? [])
18+
const showingChildren = computed(() => item.children?.filter(child => !child.meta?.hidden) ?? [])
2119
2220
/** 显示的子菜单数量 */
2321
const showingChildNumber = computed(() => showingChildren.value.length)
@@ -31,7 +29,7 @@ const theOnlyOneChild = computed(() => {
3129
case number === 1:
3230
return showingChildren.value[0]
3331
default:
34-
return { ...props.item, path: "" }
32+
return { ...item, path: "" }
3533
}
3634
})
3735
@@ -40,10 +38,10 @@ function resolvePath(routePath: string) {
4038
switch (true) {
4139
case isExternal(routePath):
4240
return routePath
43-
case isExternal(props.basePath):
44-
return props.basePath
41+
case isExternal(basePath):
42+
return basePath
4543
default:
46-
return path.resolve(props.basePath, routePath)
44+
return path.resolve(basePath, routePath)
4745
}
4846
}
4947
</script>
@@ -60,13 +58,13 @@ function resolvePath(routePath: string) {
6058
</el-menu-item>
6159
</Link>
6260
</template>
63-
<el-sub-menu v-else :index="resolvePath(props.item.path)" teleported>
61+
<el-sub-menu v-else :index="resolvePath(item.path)" teleported>
6462
<template #title>
65-
<SvgIcon v-if="props.item.meta?.svgIcon" :name="props.item.meta.svgIcon" class="svg-icon" />
66-
<component v-else-if="props.item.meta?.elIcon" :is="props.item.meta.elIcon" class="el-icon" />
67-
<span v-if="props.item.meta?.title" class="title">{{ props.item.meta.title }}</span>
63+
<SvgIcon v-if="item.meta?.svgIcon" :name="item.meta.svgIcon" class="svg-icon" />
64+
<component v-else-if="item.meta?.elIcon" :is="item.meta.elIcon" class="el-icon" />
65+
<span v-if="item.meta?.title" class="title">{{ item.meta.title }}</span>
6866
</template>
69-
<template v-if="props.item.children">
67+
<template v-if="item.children">
7068
<Item
7169
v-for="child in showingChildren"
7270
:key="child.path"

0 commit comments

Comments
 (0)