上传多张图片的布局 flex布局 uniapp 我称它为九宫格
1 <view class="input " style="display: flex;"> 2 <span class="title" style="font—size: 16px;">图像信息:</span> 3 <view class="context" >
//主要部分 7 <view class="wrap input-border"> 8 <view class="img-wrap" v-for="(item, index) in uploadDatas"> 9 <image class="image" @tap="previewUpload" :src="item" :data-url="item" mode="aspectFill"> 10 </image>
//删除按钮 11 <text class="diy-icon-close" @tap="uploadDatas.splice(index, 1)"></text> 12 </view> 13 <view class="upload-box" @tap="uploadImg"> 14 <text class="diy-icon-cameraadd"></text> 15 </view> 16 <input hidden :value="upload" name="upload" maxlength="-1" /> 17 </view>
18 </view> 20 </view>
1 export default { 2 data() { 3 return { 4 uploadDatas: [], 5 } 6 } 7 methods:{ 8 previewUpload(e) { 9 console.log('预览', e); 10 uni.previewImage({ 11 current: e.currentTarget.dataset.url, // 当前显示图片的http链接 12 urls: [e.currentTarget.dataset.url] // 需要预览的图片http链接列表 13 }); 14 }, 15 //上传 16 uploadUpload(e) { 17 this.uploadImage(this, 'upload'); 18 }, 19 20 } 21 }
1 .wrap { 2 display: flex; 3 flex-wrap: wrap; 4 } 5 6 .img-wrap { 7 position: relative; 8 display: flex; 9 flex-direction: row; 10 flex-wrap: wrap; 11 } 12 13 .img-wrap .image { 14 width: 80px; 15 height: 80px; 16 margin: 0 5px 5px 0; 17 } 18 19 .img-wrap text { 20 position: absolute; 21 right: 10px; 22 top: 0; 23 display: block; 24 height: 25px; 25 width: 16px; 26 border-radius: 0 0 0 5px; 27 background-color: #161417; 28 color: #fff; 29 } 30 31 .upload-box { 32 background-color: #F7F8FA; 33 width: 80px; 34 height: 80px; 35 line-height: 80px; 36 text-align: center; 37 }
分类:
uniapp
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 无需6万激活码!GitHub神秘组织3小时极速复刻Manus,手把手教你使用OpenManus搭建本
· Manus爆火,是硬核还是营销?
· 终于写完轮子一部分:tcp代理 了,记录一下
· 别再用vector<bool>了!Google高级工程师:这可能是STL最大的设计失误
· 单元测试从入门到精通