该 Vue.js 代码用于创建一个具有多个标签页签的多标签卡片页面。此类页面通常用于组织和显示不同类型的信息或内容,例如产品详细信息、用户资料或统计数据。
此代码的主要功能如下:
<template>
<div class="page">
<div class="header">
<div class="back-icon" @click="goBack">
<svg>...</svg>
</div>
<div class="title">The Striped Hyena</div>
<div class="more-icon">
<svg>...</svg>
</div>
</div>
<div class="content">
<div class="banner">
<img :src="`https://source.unsplash.com/random/375x200`" alt="The Striped Hyena" />
</div>
<div class="tabs">
<div class="tab" :class="{ active: tab === 'general' }" @click="tab = 'general'">
General
</div>
<div class="tab" :class="{ active: tab === 'gallery' }" @click="tab = 'gallery'">
Gallery
</div>
<div class="tab" :class="{ active: tab === 'reports' }" @click="tab = 'reports'">
Reports
</div>
</div>
<div class="tab-content">
<div v-if="tab === 'general'" class="general">...</div>
<div v-if="tab === 'gallery'" class="gallery">...</div>
<div v-if="tab === 'reports'" class="reports">...</div>
</div>
</div>
<div class="footer">...</div>
</div>
</template>
tabs
部分包含三个标签页签,当用户点击时会触发 tab
变量的变化,从而切换到相应的卡片内容面板。<script lang="tsx" setup>
import { ref, onMounted } from 'vue'
const tab = ref('general')
const images = [
'https://source.unsplash.com/random/375x200',
'https://source.unsplash.com/random/375x200',
'https://source.unsplash.com/random/375x200',
'https://source.unsplash.com/random/375x200',
'https://source.unsplash.com/random/375x200',
'https://source.unsplash.com/random/375x200',
]
onMounted(() => {
// Do something after the page is mounted
})
const goBack = () => {
// Go back to the previous page
}
</script>
setup
函数使用 Vue.js 的 ref
和 onMounted
钩子来管理组件状态和生命周期。tab
变量用于跟踪当前选定的标签页签。images
数组包含了用于填充画廊卡片的图像 URL。onMounted
钩子在组件挂载后执行,可以在这里执行初始化操作。.page {
height: 100vh;
width: 100vw;
overflow: hidden;
background-color: #fff;
}
.header {
position: fixed;
top: 0;
left: 0;
right: 0;
height: 56px;
padding: 0 16px;
background-color: #fff;
box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
display: flex;
align-items: center;
justify-content: space-between;
}
.content {
margin-top: 56px;
padding: 16px;
}
.tabs {
display: flex;
align-items: center;
justify-content: space-around;
margin-top: 16px;
}
.tab {
cursor: pointer;
padding: 8px 16px;
border-radius: 4px;
font-size: 16px;
font-weight: 500;
color: #333;
}
.tab.active {
background-color: #007bff;
color: #fff;
}
.tab-content {
margin-top: 16px;
}
active
样式,并更改背景颜色和文本颜色。此 Vue.js 代码提供了构建多标签卡片页面的基础。该代码可以根据需要进行扩展和定制,以满足特定的应用程序要求。
开发经验与收获:
ref
和 onMounted
钩子来管理组件状态和生命周期的用法。v-if
指令动态显示内容。未来该卡片功能的拓展与优化: