<md_tabs>
<md_tab_pane title="标签一">1md_tab_pane>
<md_tab_pane title="标签二">2md_tab_pane>
<md_tab_pane title="标签三">3md_tab_pane>
md_tabs>
<template>
<div class="components-md-tabs">
<header class="header">
<div
v-for="item in items"
:key="item.title"
:class="`header-btn ${
active === item.title ? 'header-btn-active' : ''
}`"
@click="active = item.title"
>
{{ item.title }}
div>
header>
<main ref="ref_main">
<slot />
main>
div>
template>
<script setup>
import { ref, provide, onMounted } from "vue";
const items = ref([]);
const ref_main = ref();
const active = ref();
provide("active", active);
onMounted(() => {
get_items();
});
function get_items() {
let doms = [...ref_main.value.children];
let arr = [];
doms.forEach((node) => {
arr.push({
title: node.dataset.title
});
});
active.value = arr[0].title;
items.value = arr;
}
script>
<style lang="scss" scoped>
.components-md-tabs {
.header {
background: #f8f9fa;
height: 60px;
border-bottom: 1px solid #e9eaeb;
display: flex;
}
.header-btn {
height: 60px;
cursor: pointer;
flex: 1;
display: flex;
align-items: center;
justify-content: center;
letter-spacing: 1px;
}
.header-btn:hover {
background: rgba(0, 0, 0, 0.1);
}
.header-btn-active {
color: var(--primary-color);
border-bottom: 2px solid var(--primary-color);
}
}
style>
<template>
<div v-show="active === title" :data-title="title">
<slot />
div>
template>
<script setup>
import { inject } from "vue";
const props = defineProps({
title: {
type: String,
default: ""
}
});
const active = inject("active");
script>
博主开发了一个浏览器aweb123.com