用vue写一个百度热搜详情页面,参考地址如下:https://top.baidu.com/board?platform=pc&tab=homepage&sa=pc_index_homepage_all
时间: 2024-04-06 19:32:05 浏览: 69
好的,我可以给您提供一个基础的 Vue 组件代码,您可以根据需求进行修改和补充。
```vue
<template>
<div class="hot-search-detail">
<div class="hot-search-header">
<h2>{{ title }}</h2>
<span>{{ date }}</span>
</div>
<div class="hot-search-list">
<ul>
<li v-for="(item, index) in list" :key="index">
<div class="rank">{{ item.rank }}</div>
<div class="title">
<a :href="item.url" target="_blank">{{ item.title }}</a>
<span v-if="item.is_new" class="new">新</span>
<span v-if="item.is_hot" class="hot">热</span>
</div>
<div class="hot-index">{{ item.hot_index }}</div>
</li>
</ul>
</div>
</div>
</template>
<script>
export default {
name: 'HotSearchDetail',
props: {
title: {
type: String,
required: true
},
date: {
type: String,
required: true
},
list: {
type: Array,
required: true
}
}
}
</script>
<style scoped>
/* 样式请根据需求进行修改 */
.hot-search-detail {
max-width: 1200px;
margin: 0 auto;
padding: 20px;
}
.hot-search-header {
display: flex;
justify-content: space-between;
align-items: center;
margin-bottom: 20px;
}
.hot-search-list ul {
list-style: none;
margin: 0;
padding: 0;
}
.hot-search-list li {
display: flex;
align-items: center;
margin-bottom: 10px;
}
.hot-search-list li .rank {
margin-right: 10px;
font-weight: bold;
font-size: 20px;
color: #f00;
}
.hot-search-list li .title {
flex: 1;
}
.hot-search-list li .title a {
color: #333;
text-decoration: none;
}
.hot-search-list li .title a:hover {
text-decoration: underline;
}
.hot-search-list li .title .new,
.hot-search-list li .title .hot {
font-size: 12px;
color: #fff;
margin-left: 10px;
padding: 2px 5px;
border-radius: 5px;
}
.hot-search-list li .title .new {
background-color: #00bfff;
}
.hot-search-list li .title .hot {
background-color: #ff4500;
}
.hot-search-list li .hot-index {
margin-left: 10px;
font-size: 16px;
color: #666;
}
</style>
```
这是一个简单的组件示例,包含一个热搜标题、日期和热搜列表。您可以在父组件中传入数据,例如:
```vue
<template>
<div class="hot-search-page">
<HotSearchDetail :title="title" :date="date" :list="list" />
</div>
</template>
<script>
import HotSearchDetail from '@/components/HotSearchDetail'
export default {
name: 'HotSearchPage',
components: {
HotSearchDetail
},
data() {
return {
title: '2021年4月9日百度风云榜',
date: '2021年4月9日',
list: [
{
rank: 1,
title: '破晓电影节',
url: 'https://www.baidu.com/link?url=VwIaD-aWz1o8CwqTqZwv8m3v2S2KXaB9QI8Jw8cB6QVZ1cXcZ8iZB5bf_9JUk9GZ6XfLxjJrC5IX0QY1VJbCJNcPDi-BQuL8jMz8VXz1y0i',
is_hot: true,
hot_index: 111
},
{
rank: 2,
title: '李宇春新歌',
url: 'https://www.baidu.com/link?url=J8t_3j5TRJ0QwGN2vTz5ZJUvLbF5WQlQH9aJhwEz1qK',
is_new: true,
hot_index: 98
},
// ...
]
}
}
}
</script>
<style scoped>
/* 样式请根据需求进行修改 */
.hot-search-page {
background-color: #f5f5f5;
min-height: 100vh;
}
</style>
```
这里只是提供一个基础的示例,实际上您需要根据实际需求进行修改和扩展,例如从后端获取数据动态渲染等。
阅读全文