uniapp图片自适应_uniapp 仿微信朋友圈,微博晒图 图片自适应排版

data() {return{

imgPicList: [],

imgboxtype:0,

imgwidth:0,

imgpad:0,

imgheight:''}

},

props: {

imgList: {

type: Array

},

num: {

type: Number,default: 0},

pad: {

type: Number,default: 0}

},

methods: {//图片预览

previewpic(cind, clist) {

console.log(cind, clist);

uni.previewImage({

urls: clist,

current: cind,

indicator:'default'});

},

getheight() {

let that= this;const query = uni.createSelectorQuery().in(that)

query.select('.imgitem').boundingClientRect()

query.exec(function(res) {

console.log(res[0].width)if (that.num == 1) {

that.imgheight= '100%';

}else if (that.num == 2 || that.num == 4) {

that.imgheight= (res[0].width).toFixed(2) + 'px';

}else{

that.imgheight= (res[0].width).toFixed(2) + 'px';

}

})//const query = uni.createSelectorQuery().in(this).select('.imgitem');//uni.createSelectorQuery().select('.imgitem').boundingClientRect(res => {//console.log('reac', res)//if (this.num == 1) {//this.imgheight = '100%';//} else if (this.num == 2 || this.num == 4) {//this.imgheight = (res.width).toFixed(2) + 'px';//} else {//this.imgheight = (res.width).toFixed(2) + 'px';//}//}).exec()

}

},

mounted() {//let this = this;

this.imgPicList = this.imgList;if (this.num == 1) {this.imgboxtype = 0;this.imgwidth = 100 + '%';

}else if (this.num == 2 || this.num == 4) {this.imgboxtype = 1;this.imgwidth = 49 + '%';

}else if (this.num == 3 || this.num > 4) {this.imgboxtype = 2;this.imgwidth = 32 + '%';

}this.$nextTick(function() {this.getheight();

})

}

}

.flex {

display: flex;

}

.justify {

justify-content: space-between;

}

.receiveimage {

margin-top: 28rpx;

display: flex;

flex-wrap: wrap;

width:100%;

.onepic {

width:100%;//height: 188rpx;//height: auto;

margin-bottom: 28rpx;&:nth-child(3n) {

margin-right: 0;

}

}

.doublepic {//width: 340rpx;//height: 340rpx;

margin-right: 12rpx;

margin-bottom: 12rpx;&:nth-child(2n) {

margin-right: 0;

}

}

.triplepic {//width: 222rpx;//height: 222rpx;

margin-right: 12rpx;

margin-bottom: 12rpx;&:nth-child(3n) {

margin-right: 0;

}

}

}

}

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值