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

33 lines
648 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-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 {
2023-11-24 11:02:52 +00:00
font-size: 20px;
2023-11-03 09:45:01 +00:00
}
</style>