71 lines
1.4 KiB
Vue
Raw Normal View History

2021-03-25 22:33:41 +08:00
<template>
<div class="container">
<nav>
2021-04-04 00:17:54 +08:00
<div :id="tag" class="nav nav-pills" role="tablist">
2021-03-25 22:33:41 +08:00
<button
v-for="tab of children"
:id="tab.labelID"
:aria-controls="tab.tabID"
2021-04-04 00:17:54 +08:00
:data-bs-target="'#' + tab.tabID"
2021-03-25 22:33:41 +08:00
aria-selected="false"
2021-04-04 00:17:54 +08:00
class="nav-link"
data-bs-toggle="tab"
role="tab"
type="button"
2021-03-25 22:33:41 +08:00
>
{{ tab.title }}
</button>
</div>
</nav>
2021-03-26 10:15:33 +08:00
<div :id="contentTag" class="tab-content">
2021-03-25 22:33:41 +08:00
<slot />
</div>
</div>
</template>
<script lang="ts">
2021-04-06 23:47:32 +08:00
import { defineComponent } from "vue";
2021-03-25 22:33:41 +08:00
2021-04-06 23:47:32 +08:00
export default defineComponent({
2021-03-25 22:33:41 +08:00
props: {
title: {
2021-04-04 14:38:46 +08:00
type: String,
},
2021-03-25 22:33:41 +08:00
},
data() {
return {
2021-04-04 14:38:46 +08:00
children: [],
2021-03-25 22:33:41 +08:00
};
},
2021-04-06 23:47:32 +08:00
beforeMount() {
2021-04-04 14:38:46 +08:00
this.children = [];
2021-03-25 22:33:41 +08:00
},
mounted() {
2021-04-04 14:38:46 +08:00
this.$nextTick(function () {
2021-05-03 12:57:54 +08:00
import("bootstrap").then((b) => {
let triggerEl = document.getElementById(
this.children["0"].$data.labelID
);
new b.Tab(triggerEl).show();
});
2021-03-25 22:33:41 +08:00
});
},
computed: {
2021-04-04 14:38:46 +08:00
tag: function () {
2021-03-25 22:33:41 +08:00
return "tabs-" + this.title;
2021-03-26 10:15:33 +08:00
},
2021-04-04 14:38:46 +08:00
contentTag: function () {
2021-03-26 10:15:33 +08:00
return "tabs-" + this.title + "-content";
2021-04-04 14:38:46 +08:00
},
},
2021-03-25 22:33:41 +08:00
});
</script>
<style lang="scss" scoped>
2021-05-03 12:57:54 +08:00
@import "node_modules/bootstrap/scss/bootstrap";
2021-04-04 00:17:54 +08:00
button.nav-link {
2021-04-06 23:47:32 +08:00
color: var(--textColor);
2021-04-04 00:17:54 +08:00
}
2021-03-25 22:33:41 +08:00
</style>