我只需要显示内容,有标题和内容还有图片就行,不用搜索功能什么的
时间: 2024-04-27 10:24:46 浏览: 3
好的,那我可以为您提供一个简单的新闻列表页和详情页代码,仅包含标题、内容和图片。请参考以下代码:
新闻列表页代码:
```html
<view class="container">
<scroll-view class="news-list" scroll-y>
<view class="news-item" wx:for="{{newsList}}" wx:key="index" bindtap="goToDetail">
<image class="news-img" src="{{item.imgUrl}}"></image>
<view class="news-text">
<view class="news-title">{{item.title}}</view>
<view class="news-content">{{item.content}}</view>
</view>
</view>
</scroll-view>
</view>
```
```javascript
Page({
data: {
// 新闻列表
newsList: [
{
title: '新闻标题1',
content: '新闻内容1',
imgUrl: 'https://example.com/news1.jpg'
},
{
title: '新闻标题2',
content: '新闻内容2',
imgUrl: 'https://example.com/news2.jpg'
},
{
title: '新闻标题3',
content: '新闻内容3',
imgUrl: 'https://example.com/news3.jpg'
}
// ...更多新闻
]
},
// 跳转到新闻详情页
goToDetail(e) {
const index = e.currentTarget.dataset.index
wx.navigateTo({
url: `/pages/news-detail/index?index=${index}`
})
}
})
```
新闻详情页代码:
```html
<view class="container">
<view class="news-header">
<view class="news-title">{{newsDetail.title}}</view>
</view>
<image class="news-img" src="{{newsDetail.imgUrl}}"></image>
<rich-text nodes="{{newsDetail.content}}"></rich-text>
</view>
```
```javascript
Page({
data: {
// 新闻详情
newsDetail: {}
},
onLoad(options) {
// 从列表页传过来的index参数
const index = options.index
// 根据index获取对应的新闻详情
const newsList = wx.getStorageSync('newsList') || []
const newsDetail = newsList[index]
this.setData({
newsDetail
})
}
})
```
以上代码仅供参考,具体的实现方式还需要根据具体需求进行调整。