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

31 lines
607 B
Vue
Raw Normal View History

2023-10-27 09:49:06 +00:00
<template>
2023-11-03 09:45:01 +00:00
<el-icon class="back-button cursor mr-8" @click="jump">
2023-10-27 09:49:06 +00:00
<Back />
</el-icon>
</template>
<script setup lang="ts">
import { useRouter, type RouteLocationRaw } from 'vue-router'
defineOptions({ name: 'BackButton' })
const router = useRouter()
const props = defineProps({
to: String
})
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)
} else {
router.push(props.to as RouteLocationRaw)
}
}
</script>
2023-11-03 09:45:01 +00:00
<style lang="scss">
.back-button {
font-size:20px;
}
</style>