feat: 添加自定义返回按钮组件并替换现有页面中的返回按钮
This commit is contained in:
26
src/ui/back-button/index.vue
Normal file
26
src/ui/back-button/index.vue
Normal file
@@ -0,0 +1,26 @@
|
||||
<script lang='ts' setup>
|
||||
import { chevronBackOutline } from "ionicons/icons";
|
||||
|
||||
const { text = "返回" } = defineProps<{
|
||||
text?: string;
|
||||
}>();
|
||||
const router = useRouter();
|
||||
|
||||
function onBack() {
|
||||
if (window.history.length > 1) {
|
||||
router.back();
|
||||
}
|
||||
else {
|
||||
router.replace("/");
|
||||
}
|
||||
}
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<button class="z-1 flex items-center" @click="onBack">
|
||||
<ion-icon :icon="chevronBackOutline" class="text-2xl" />
|
||||
<span v-if="text" class="text-base">{{ text }}</span>
|
||||
</button>
|
||||
</template>
|
||||
|
||||
<style lang='css' scoped></style>
|
||||
@@ -35,5 +35,6 @@ declare module "vue" {
|
||||
UiTabs: typeof import("./tabs/index.vue")["default"];
|
||||
UiTag: typeof import("./tag/index.vue")["default"];
|
||||
UiTextareaLabel: typeof import("./textarea-label/index.vue")["default"];
|
||||
UiBackButton: typeof import("./back-button/index.vue")["default"];
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user