微信小程序资讯列表

在这里插入图片描述

<view class="news-list">
  <block wx:for="{{newsList}}" wx:key="index">
    <view class="news-item" bindtap="showDetails" data-index="{{index}}">
      <image class="news-image" src="{{item.image}}" mode="aspectFill"></image>
      <view class="news-content">
        <view class="news-title-container">
          <text class="news-title">{{item.title}}</text>
        </view>
        <view class="news-description-container">
          <text class="news-description">{{item.description}}</text>
        </view>
        <view class="news-meta">
          <text class="news-view-count">浏览:{{item.viewCount}}</text>
          <text class="news-publish-time">发布时间:{{item.publishTime}}</text>
        </view>
      </view>
    </view>
  </block>
</view>
page {
  display: flex;
  flex-direction: column;
  background-color: #f5f2f2;
}

.news-list {
  display: flex;
  flex-direction: column;
  padding: 20rpx;
  width: 100%;
  padding-bottom: env(safe-area-inset-bottom);
}

.news-item {
  display: flex;
  padding: 20rpx;
  margin-bottom: 20rpx;
  border: 1px solid #eaeaea;
  border-radius: 12rpx;
  background-color: #ffffff;
  box-shadow: 0 2px 10px rgba(0, 0, 0, 0.05);
  width: calc(100% - 40rpx);
  box-sizing: border-box;
  flex-direction: row;
  cursor: pointer;
}

.news-image {
  width: 200rpx;
  height: 200rpx;
  margin-right: 20rpx;
  border-radius: 8rpx;
  object-fit: cover;
  flex-shrink: 0;
  flex-grow: 0;
}

.news-content {
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  flex: 1;
  padding-left: 20rpx;
}

.news-title-container {
  display: flex;
  align-items: center;
}

.news-title {
  font-size: 32rpx;
  color: #333333;
  font-weight: bold;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.news-description-container {
  margin-top: 10rpx;
}

.news-description {
  font-size: 28rpx;
  color: #666666;
  line-height: 1.5;
  overflow: hidden;
  text-overflow: ellipsis;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
}

.news-meta {
  display: flex;
  justify-content: space-between;
  margin-top: 10rpx;
  font-size: 24rpx;
  color: #999999;
}
Page({
  data: {
    newsList: [
      {
        image: '/images/none.png',
        title: '微信小程序',
        description: '微信小程序描述微信小程序描述微信小程序描述',
        viewCount: '1234',
        publishTime: '2024-10-23'
      },
      {
        image: '/images/more.png',
        title: 'UNIAPP',
        description: 'UNIAPP描述UNIAPP描述UNIAPP描述UNIAPP描述',
        viewCount: '5678',
        publishTime: '2024-10-22'
      },
    ]
  },
  showDetails: function (e) {
    const index = e.currentTarget.dataset.index;
    const item = this.data.newsList[index];
    
    wx.showModal({
      title: `${item.title}`,
      content: `${item.description}`,
      showCancel: true,
      cancelText: '取消',
      confirmText: '确认',
      success: function (res) {
        if (res.confirm) {
          console.log('用户点击确定');
        } else if (res.cancel) {
          console.log('用户点击取消');
        }
      }
    });
  },
  onLoad: function () {
  }
});
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值