微信小程序实例代码

实现效果:
在这里插入图片描述
index.wxml:

<view class="container">

  <view class="selection" style="border:0">
  
     <swiper indicator-dots="true"
     autoplay="true" interval="3000" duration="1000">
        <block wx:for="{{imgUrls}}">
           <swiper-item>
              <image src="{{item}}" width="355" height="150"/>
           </swiper-item>
         </block>
      </swiper>
      
   </view>
   
  <view class="selection">
  
    <view class="header">
       <text>精品推荐</text>
       <text class="text-all">全部精品</text>
    </view>
    
    <view class="content">
       <view class="content-item" wx:for="{{contentItems}}">
          <image src="../../images/img1.jpg"/>
             <view class="content-item-text">
                <text>这里是标题</text>
             </view>
          </view>
      </view>
   </view>
   
   <view class="selection">
   
      <view class="header">
         <text>热门评测</text>
         <text class="text-all">全部评测</text>
      </view>
      
      <view class="list-item" wx:for="{{listItems}}">
      
         <view class="list-item-images">
            <image src="../../images/img2.jpg" class="list-item-images-img"/>        <image src="../../images/avatar.jpeg" class="avatar"/>
         </view>
         
         <view class="list-item-text">
         
            <view class="list-item-text-title">
               <text>标题标题标题标题</text>
            </view>
            
            <view class="list-item-text-content">
               <text>这里是内容,这里是内容,这里是内容,这里是内容,这里是内容,这里是内容,这里是内容,这里是内容,</text>
            </view>
            
         </view>
      </view>
   </view>
</view>

index.wxss:

.selection{
  border-bottom: 4px solid #ddd;
}

.header{
  border-left-width: 2px;
  border-left-style: solid;
  border-left-color: limegreen;
  display: flex;
  justify-content: space-between;
  align-items: center;
  height: 60rpx;
  padding-left: 30rpx;
  padding-right: 30rpx;
  margin-top: 30rpx;
  margin-bottom: 30rpx;
}

.text-all{
  color: limegreen;
  font-size: 10px;
}

.content{
  display: flex;
  flex-direction: row;
  flex-wrap: wrap;
  justify-content: center;
  margin-bottom: 5px;
}

.content-item{
  height: 250rpx;
  width: 45%;
  margin: 5px;
  position: relative;
}

.content-item image{
  width: 100%;
  height: 100%;
}

.content-item-text{
  position: absolute;
  bottom: 0px;
  color: white;
  font-size: 10px;
  background: -webkit-linear-gradient(bottom,rgba(0,0,0,0.8),rgba(0,0,0,0));
  height: 125rpx;
  width: 90%;
  display: flex;
  flex-direction: column;
  justify-content: flex-end;
  padding-left: 5%;
  padding-right: 5%;
  padding-bottom: 3%;
}

.list-item{
  height: 500rpx;
  width: 100%;
}

.list-item-images{
  height: 300rpx;
  width: 100%;
  position: relative;
}

.list-item-images-img{
  height: 100%;
  width: 100%;
}

.avatar{
  width: 100rpx;
  height: 100rpx;
  border-radius: 50%;
  position: absolute;
  bottom: -50rpx;
  right: 50rpx;
}

.list-item-text{
  height: 200rpx;
  width: 96%;
  margin-top: 30rpx;
  padding:0 3%;
}

.list-item-text-title{
  font-weight: bold;
}

.list-item-text-content{
  font-size: 10px;
  color: #999;
  margin-top: 20rpx;
}

index.js:

Page({
  data: {
     imgUrls:[
        'https://i.loli.net/2020/02/21/gtN1icMTrALFPfb.jpg',
        'https://i.loli.net/2020/02/21/42pTOevfVio1jWs.png',
        'https://i.loli.net/2020/02/21/9elxq8TuMvWtRgs.jpg'
      ],
      contentItems:['','','',''],
      listItems: ['', '', '', '','', '', '']
   }
})

总结:
通过几天的学习,我学会了使用view和swiper插件,学会了flew分布,学会了将text的背景颜色设为半透明,学会了编写简单的微信小程序

  • 1
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
当然可以,以下是一个简单的微信小程序实例代码示例: ``` <!--index.wxml--> <view class="container"> <view class="title">生成数字卡片</view> <view class="content"> <text>请输入数字:</text> <input placeholder="请输入数字" bindinput="inputNumber"/> <button bindtap="generateCards">生成卡片</button> </view> <view class="card-container"> <block wx:for="{{cards}}" wx:key="index"> <view class="card">{{item}}</view> </block> </view> </view> //index.js Page({ data: { number: 0, cards: [] }, inputNumber(event) { this.setData({ number: event.detail.value }) }, generateCards() { const number = parseInt(this.data.number) if (isNaN(number) || number <= 0) { wx.showToast({ title: '请输入大于0的数字', icon: 'none', duration: 2000 }) return } const cards = [] for (let i = 1; i <= number; i++) { cards.push(i) } this.setData({ cards: cards }) } }) //index.wxss .container { display: flex; flex-direction: column; align-items: center; justify-content: center; height: 100vh; } .title { font-size: 24px; margin-bottom: 20px; } .content { display: flex; align-items: center; justify-content: center; margin-bottom: 20px; } .text { font-size: 14px; margin-right: 10px; } input { height: 30px; width: 120px; border: 1px solid #ccc; border-radius: 4px; padding: 0 10px; margin-right: 10px; } button { height: 30px; width: 60px; background-color: #4CAF50; color: #fff; border: none; border-radius: 4px; } .card-container { display: flex; flex-wrap: wrap; justify-content: center; } .card { display: flex; align-items: center; justify-content: center; height: 100px; width: 100px; margin: 10px; background-color: #f1f1f1; border: 1px solid #ccc; border-radius: 4px; font-size: 24px; } ``` 这个微信小程序包括一个页面,其中包含一个输入框和一个生成卡片的按钮。当用户输入数字并点击按钮时,会生成对应数量的数字卡片并按照从上到下,从左到右的顺序排列。如果用户输入的不是大于0的数字,则会提示用户重新输入。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值