微信小程序push数据到data列表渲染到页面

遇到问题不要慌
在这里插入图片描述

push数据data 渲染到页面实现效果图

在这里插入图片描述
点击上传图片,在页面会渲染多一个照片列表
在这里插入图片描述
在这里插入图片描述
点击删除会减少一个图片列表渲染
在这里插入图片描述
在这里插入图片描述

要实现的功能已经介绍完了,(就不说废话了,上代码)

.wxml文件

<view class="uploadPic-content">
          <view class="uploadPic-info" wx:for="{{imgListArr}}" wx:key="{{index}}">
            <view class="uploadPic-info-header">
              <view class="img-tit">照片{{index+1}}</view>
              <view class="delete" bindtap="delPicture">删除</view>
            </view>
            <view class="item">
              <text>照片标题 *</text>
              <input name="imgTitle" type="text" placeholder="请输入" />
            </view>
            <view class="item">
              <text>拍摄方向 *</text>
              <input name="imgDirection" type="text" placeholder="请输入" />
            </view>
            <view class="item-addImg">
                <view class="addImg" bindtap="toUploadImg">
                    <image src="../images/uploadImg.png"></image>
                    <text class="addImg-tit" >上传图片</text>
                </view>
            </view>
          </view>
    </view>
    <view class="uploadPic">
        <view class="upload-img" bindtap="addShowMadel">上传图片</view>
    </view>

wxss.文件


page{
    background-color: #f3f4f5;
    min-height: 100vh ;
}
.uploadPic{
    padding: 30rpx 80rpx;
  }
  .item{
    display: flex;
    justify-content: space-between;
    align-items: center;
    height: 98rpx;
    padding: 0 30rpx;
    border-bottom: 2px solid #F4F5F6;
    background-color: #fff;
    font-size: 28rpx;
  }
  input{
    text-align: right;
  }
  .upload-img{
    height: 88rpx;
    line-height: 88rpx;
    text-align: center;
    border: 1px dashed #999;
    opacity: 1;
    border-radius: 20rpx;
    font-size: 36rpx;
    font-family: Microsoft YaHei;
    font-weight: 400;
    color: #333333;
  }
  .uploadPic-info-header{
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 20rpx 30rpx;
  }
  .uploadPic-info-header .img-tit{
    font-size: 30rpx;
    font-family: Microsoft YaHei;
    font-weight: 400;
    color: #999999;
  }
  .uploadPic-info-header .delete{
    font-size: 30rpx;
    font-family: Microsoft YaHei;
    font-weight: 400;
    color: #E70012;
  }
  
  .item-addImg{
    padding: 30rpx;
    background-color: #fff;
  }
  
  .addImg{
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    width: 214rpx;
    height: 214rpx;
    border: 1px solid #B5B5B5;
    border-radius: 13px;
    text-align: center;
  
  }
  
  .addImg image{
    width: 80rpx;
    height: 80rpx;
  }
  
  .addImg .addImg-tit{
    margin-top: 10rpx;
    font-size: 30rpx;
    font-family: Microsoft YaHei;
    font-weight: 400;
    color: #999;
  }

.js文件

// pages/uploadImg/uploadImg.js
Page({

    /**
     * 页面的初始数据
     */
    data: {
        imgListArr:[
              {
              imgTitle: '' , //照片标题
              imgDirection: '' , //拍摄方向
            }
          ],  //上传图片   
    },
      // 添加图片数组
  addShowMadel(){
    let picture = {
      imgTitle: '', //照片标题
      imgDirection: '', //拍摄方向
    };
    this.data.imgListArr.push(picture);
    this.setData({
      imgListArr:this.data.imgListArr
    })
    // console.log(this.data.imgListArr);
  },
  // 删除图片数组
  delPicture(index){
    this.data.imgListArr.splice(index, 1);
    this.setData({
      imgListArr:this.data.imgListArr
    })
    // console.log(this.data.imgListArr);

  },
   
})

添加图片的图标
在这里插入图片描述

  • 1
    点赞
  • 6
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值