小程序显示图片并且预览

	<view class="cont_list" style="padding: 20rpx 30rpx;">
					<view v-if="imgArr.length>0">
						<!-- <image v-for="(item,index) in imgArr" :key="index" class="img" :src="item"></image> -->
						<view class="u-page">
							<view class="u-demo-block">
								<view class="u-demo-block__content">
									<view class="album">
										<view class="album__content">
											<!-- rowCount每行展示图片数量,默认每行显示3个,如设置rowCount,singleSize和multipleSize将会无效 -->
											<u-album singleSize="80" multipleSize="80" space="8" rowCount="4" :urls="imgArr"></u-album>
										</view>
									</view>
								</view>
							</view>
						</view>
					</view>
					<view v-else style="padding: 30rpx 0;">暂无图片</view>
				</view>

 


				.cont_list {
					background: #FFFFFF;
					border-radius: 12rpx;
					margin-top: 20rpx;
					padding: 0 30rpx;
					font-weight: 400;
					font-size: 14px;
					color: #212121;
					line-height: 20px;
					text-align: left;
					font-style: normal;
					.cont_list_li {
						display: flex;
						justify-content: space-between;
						padding: 28rpx 0 24rpx;
						border-bottom: 2rpx solid #ddd;
						&:last-child {
							border-bottom: 0;
						}
						.li_fl {
							font-weight: 400;
							font-size: 14px;
							color: #212121;
						}
						.li_fr {
							font-weight: 500;
							font-size: 14px;
							color: #212121;
						}
					}
				}

 

export default {
		data() {
			return {

				imgArr: [],
            }
        },

		onLoad(option) {
			// console.log(option)
			if(option.intelligence1Image) {
				this.imgArr.push(option.intelligence1Image)
			}
			if(option.intelligence2Image) {
				this.imgArr.push(option.intelligence2Image)
			}
			if(option.intelligence3Image) {
				this.imgArr.push(option.intelligence3Image)
			}
			if(option.intelligence4Image) {
				this.imgArr.push(option.intelligence4Image)
			}
			// console.log(this.imgArr)
		},
}

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
好的,我来为您介绍如何自己封装一个基于小程序图片预览组件。 1. 创建组件文件夹 在小程序项目中创建一个名为 "image-preview" 的文件夹,用于存放图片预览组件相关的文件。 2. 创建组件的wxml文件 在 "image-preview" 文件夹中创建一个名为 "image-preview.wxml" 的文件,用于编写图片预览组件的模板代码。在模板代码中,我们可以使用 `wx:for` 循环渲染图片列表,并且利用 `wx:if` 判断当前图片是否为预览图片。同时,我们需要为图片添加点击事件,当图片被点击时,触发预览图片的方法。 一个简单的 "image-preview" 组件模板代码如下: ```html <view class="preview-container" bindtap="previewImage"> <image wx:for="{{images}}" wx:key="{{index}}" src="{{item}}" mode="{{mode}}" class="preview-image" wx:if="{{index === current}}" /> </view> ``` 3. 创建组件的js文件 在 "image-preview" 文件夹中创建一个名为 "image-preview.js" 的文件,用于编写图片预览组件的逻辑代码。在逻辑代码中,我们需要定义组件的属性、方法和生命周期函数。 首先,我们需要定义组件的属性。组件的属性包括: - images:预览图片列表,可以是本地图片路径或者网络图片链接; - current:当前预览图片索引,默认为 0; - mode:预览模式,支持缩放和不缩放两种模式; - indicator-dots:是否显示指示点,默认为 true; - autoplay:是否自动播放,默认为 false; - interval:自动播放时间间隔,默认为 5000ms。 代码如下: ```javascript Component({ properties: { images: { type: Array, value: [], }, current: { type: Number, value: 0, }, mode: { type: String, value: 'aspectFit', }, indicatorDots: { type: Boolean, value: true, }, autoplay: { type: Boolean, value: false, }, interval: { type: Number, value: 5000, }, }, methods: { previewImage() { wx.previewImage({ current: this.properties.images[this.properties.current], urls: this.properties.images, }); }, }, }); ``` 接着,我们需要定义组件的生命周期函数。由于图片预览组件不需要特定的生命周期函数,所以我们可以忽略该步骤。 最后,我们需要在小程序页面中使用该组件。在需要预览图片的页面中引入 "image-preview" 组件,并传递需要预览图片列表和其他属性。 一个简单的页面引入组件的代码如下: ```html <image-preview images="{{imageList}}" current="{{currentIndex}}" mode="aspectFit"></image-preview> ``` 以上就是自己封装一个基于小程序图片预览组件的步骤,希望能对您有所帮助。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值