微信小程序入门与实战(8)——使用嵌套自定义组件创建电影页面

本文介绍了一个用于展示电影列表的小程序组件设计,包括电影海报、标题、评分等元素的布局和样式实现。通过使用自定义组件的方式,实现了电影信息的模块化展示。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

在这里插入图片描述

components/movie/index

index.wxml

<!--components/moive/index.wxml-->
<view class="container">
  <image class="poster" src="/img/iqiyi.png"></image>
    <text class="title">盗梦空间</text>
    <view class="rate-container">
    <l-rate disabled="{{true}}" size="22" score="3" />

    <text class="score">3</text>
    </view>
</view>

index.wxss

/* components/moive/index.wxss */
.container{
  display: flex;
  flex-direction: column;
  width: 200rpx;
}

.poster{
  width: 100%;
  height: 270rpx;
  margin-bottom: 22rpx;
}

.title{
  white-space: nowrap;
  text-overflow: ellipsis;
  overflow: hidden;
  word-break: break-all;
}

.rate-container{
  margin-top:6rpx;
  display: flex;
  flex-direction: row;
  align-items: baseline;
}

.score{
  margin-left:20rpx;
  font-size:24rpx;
}


index.json

{
  "component": true,
  "usingComponents": {
    "l-rate":"/miniprogram_npm/lin-ui/rate/index"
  }
}

components/movie-list/index

index.wxml

<!--components/movie-list/index.wxml-->
<view class="container f-class">
  <view class="title-container">
    <text>正在热映</text>
    <text class="more-text">更多 ></text>
  </view>
  <view class="movie-container">
    <movie />
    <movie />
    <movie />
  </view>
</view>

index.wxss

/* components/movie-list/index.wxss */
.container{
  padding: 36rpx 36rpx;
  background-color: #ffffff;
}

.title-container{
  display: flex;
  flex-direction: row;
  justify-content: space-between;
  margin-bottom: 28rpx;
}

.movie-container{
  display: flex;
  flex-direction: row;
  justify-content: space-between;
}

.more-text{
  color: #1f4ba5;
}

index.json

{
  "component": true,
  "usingComponents": {
    "movie":"/components/movie/index"
  }
}

pages/movie

movie.wxml

<!--pages/movies/movies.wxml-->
<movie-list f-class="movie-list" />
<movie-list f-class="movie-list" />
<movie-list f-class="movie-list" />

movie.wxss

/* pages/movies/movies.wxss */
.movie-list{
  margin-bottom: 30rpx;
}

page{
  background-color: #f2f2f2;
  /* background-color: teal; */
}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值