用vue写一个b站个人中心的页面
时间: 2024-06-09 13:10:49 浏览: 157
好的,下面是一个简单的B站个人中心页面的Vue代码:
```html
<template>
<div class="personal-center">
<div class="personal-info">
<img class="avatar" :src="user.avatar" alt="avatar">
<div class="info">
<div class="username">{{user.username}}</div>
<div class="level">{{user.level}}</div>
<div class="follow">
<span class="count">{{user.following}}</span>
<span class="label">关注</span>
<span class="count">{{user.followers}}</span>
<span class="label">粉丝</span>
</div>
</div>
</div>
<div class="tabs">
<div class="tab" :class="{active: activeTab === 'videos'}" @click="activeTab = 'videos'">视频</div>
<div class="tab" :class="{active: activeTab === 'favorites'}" @click="activeTab = 'favorites'">收藏</div>
<div class="tab" :class="{active: activeTab === 'history'}" @click="activeTab = 'history'">历史</div>
</div>
<div class="content">
<div v-if="activeTab === 'videos'" class="videos">
<div class="video" v-for="video in user.videos" :key="video.id">
<img :src="video.cover" alt="cover">
<div class="title">{{video.title}}</div>
<div class="play">{{video.play}} 播放</div>
</div>
</div>
<div v-if="activeTab === 'favorites'" class="favorites">
<div class="video" v-for="video in user.favorites" :key="video.id">
<img :src="video.cover" alt="cover">
<div class="title">{{video.title}}</div>
<div class="play">{{video.play}} 播放</div>
</div>
</div>
<div v-if="activeTab === 'history'" class="history">
<div class="video" v-for="video in user.history" :key="video.id">
<img :src="video.cover" alt="cover">
<div class="title">{{video.title}}</div>
<div class="play">{{video.play}} 播放</div>
</div>
</div>
</div>
</div>
</template>
<script>
export default {
data() {
return {
activeTab: 'videos',
user: {
avatar: 'https://i0.hdslb.com/bfs/face/1489ac9d7f8d248f8c0a2bc0d956ed7a3a3a0f7f.jpg',
username: 'Vue之家',
level: 5,
following: 120,
followers: 580,
videos: [
{
id: 1,
cover: 'https://i0.hdslb.com/bfs/archive/df2e20e6c23d57b9ee234c3e3fda5a5a5c1b013f.jpg',
title: 'Vue 3.0新特性',
play: 10086
},
{
id: 2,
cover: 'https://i0.hdslb.com/bfs/archive/4f6f1b6c4b6f228d6ef1c2d2a6f23c9e9f6d1e2d.jpg',
title: 'Vue 3.0源码解析',
play: 8888
},
{
id: 3,
cover: 'https://i0.hdslb.com/bfs/archive/3b8c7f1d13d7e1b085e44b7d8c9d9b2c84f1b1d7.jpg',
title: 'Vue 3.0实战',
play: 6666
}
],
favorites: [
{
id: 4,
cover: 'https://i0.hdslb.com/bfs/archive/3b8c7f1d13d7e1b085e44b7d8c9d9b2c84f1b1d7.jpg',
title: 'Vue 3.0实战',
play: 6666
},
{
id: 5,
cover: 'https://i0.hdslb.com/bfs/archive/4f6f1b6c4b6f228d6ef1c2d2a6f23c9e9f6d1e2d.jpg',
title: 'Vue 3.0源码解析',
play: 8888
},
{
id: 6,
cover: 'https://i0.hdslb.com/bfs/archive/df2e20e6c23d57b9ee234c3e3fda5a5a5c1b013f.jpg',
title: 'Vue 3.0新特性',
play: 10086
}
],
history: [
{
id: 2,
cover: 'https://i0.hdslb.com/bfs/archive/4f6f1b6c4b6f228d6ef1c2d2a6f23c9e9f6d1e2d.jpg',
title: 'Vue 3.0源码解析',
play: 8888
},
{
id: 1,
cover: 'https://i0.hdslb.com/bfs/archive/df2e20e6c23d57b9ee234c3e3fda5a5a5c1b013f.jpg',
title: 'Vue 3.0新特性',
play: 10086
}
]
}
}
}
}
</script>
<style scoped>
.personal-center {
width: 800px;
margin: 0 auto;
}
.personal-info {
display: flex;
align-items: center;
margin-bottom: 20px;
}
.avatar {
width: 80px;
height: 80px;
border-radius: 50%;
margin-right: 20px;
}
.info {
display: flex;
flex-direction: column;
}
.username {
font-size: 24px;
margin-bottom: 10px;
}
.level {
font-size: 16px;
color: #999;
margin-bottom: 10px;
}
.follow {
display: flex;
align-items: center;
}
.count {
font-size: 18px;
font-weight: bold;
margin-right: 5px;
}
.label {
font-size: 16px;
color: #999;
margin-right: 10px;
}
.tabs {
display: flex;
margin-bottom: 20px;
}
.tab {
font-size: 18px;
font-weight: bold;
margin-right: 20px;
cursor: pointer;
}
.tab.active {
color: #f00;
}
.content {
border: 1px solid #ccc;
padding: 20px;
}
.video {
display: flex;
flex-direction: column;
align-items: center;
margin-bottom: 20px;
}
.video img {
width: 200px;
height: 150px;
margin-bottom: 10px;
}
.video .title {
font-size: 18px;
font-weight: bold;
margin-bottom: 10px;
}
.video .play {
font-size: 16px;
color: #999;
}
</style>
```
这个页面包括了B站个人中心的基本元素,包括用户信息、视频列表、收藏列表和历史记录列表。你可以根据需要进行修改和扩展。
阅读全文