UnisKB/ui/src/components/back-button/index.vue

36 lines
727 B
Vue
Raw Normal View History

2023-10-27 09:49:06 +00:00
<template>
2023-11-24 11:02:52 +00:00
<el-button class="back-button cursor mr-4" text @click="jump">
<el-icon>
<Back />
</el-icon>
</el-button>
2023-10-27 09:49:06 +00:00
</template>
<script setup lang="ts">
import { useRouter, type RouteLocationRaw } from 'vue-router'
defineOptions({ name: 'BackButton' })
const router = useRouter()
const props = defineProps({
to: String
})
2023-12-05 11:21:13 +00:00
const emit = defineEmits(['click'])
2023-11-22 03:05:06 +00:00
/* 上一层路由 */
const back: any = router.options.history.state.back
2023-10-27 09:49:06 +00:00
function jump() {
if (props.to === '-1') {
back ? router.push(back) : router.go(-1)
2023-12-05 11:21:13 +00:00
} else if (props.to) {
2023-10-27 09:49:06 +00:00
router.push(props.to as RouteLocationRaw)
2023-12-05 11:21:13 +00:00
} else {
emit('click')
2023-10-27 09:49:06 +00:00
}
}
</script>
2023-11-03 09:45:01 +00:00
<style lang="scss">
.back-button {
2023-11-24 11:02:52 +00:00
font-size: 20px;
2023-11-03 09:45:01 +00:00
}
</style>