用uniapp写一个新闻界面
时间: 2023-06-20 20:06:05 浏览: 156
好的,以下是一个简单的新闻界面的示例代码:
```vue
<template>
<view class="news">
<view class="news-header">
<text class="news-header-title">今日新闻</text>
</view>
<view class="news-list">
<view class="news-item" v-for="(item, index) in newsList" :key="index">
<view class="news-item-image">
<image :src="item.image"></image>
</view>
<view class="news-item-content">
<text class="news-item-title">{{item.title}}</text>
<text class="news-item-summary">{{item.summary}}</text>
</view>
</view>
</view>
</view>
</template>
<script>
export default {
data() {
return {
newsList: [
{
title: "新闻标题1",
image: "https://dummyimage.com/200x200/f0f0f0/999999.png",
summary: "新闻简介1"
},
{
title: "新闻标题2",
image: "https://dummyimage.com/200x200/f0f0f0/999999.png",
summary: "新闻简介2"
},
{
title: "新闻标题3",
image: "https://dummyimage.com/200x200/f0f0f0/999999.png",
summary: "新闻简介3"
}
]
};
}
};
</script>
<style>
.news {
display: flex;
flex-direction: column;
height: 100%;
}
.news-header {
height: 50px;
background-color: #f5f5f5;
display: flex;
align-items: center;
justify-content: center;
}
.news-header-title {
font-size: 20px;
font-weight: bold;
}
.news-list {
flex: 1;
display: flex;
flex-direction: column;
padding: 20px;
}
.news-item {
display: flex;
flex-direction: row;
margin-bottom: 20px;
}
.news-item-image {
width: 200px;
height: 200px;
margin-right: 20px;
overflow: hidden;
}
.news-item-image image {
width: 100%;
height: 100%;
object-fit: cover;
}
.news-item-content {
flex: 1;
display: flex;
flex-direction: column;
}
.news-item-title {
font-size: 18px;
font-weight: bold;
margin-bottom: 10px;
}
.news-item-summary {
font-size: 14px;
color: #999;
}
</style>
```
这个示例代码使用了 `flex` 布局,将新闻列表垂直排列在一个容器中。每个新闻条目由一个图片和标题、简介组成。示例代码中的图片使用了一个占位图片,实际使用时需要替换成真实图片的 URL。
阅读全文