uniapp+uview 图片预览组件

uniapp + uview 图片列表预览组件

注意:在app端需要先判断是否存在手机相册权限

html 复制代码
<template>
	<!-- css使用的是uview1.0组件中的css -->
	<!-- u-image  使用的是uview1.0的组件 -->
	<view class="u-flex u-row-between u-flex-wrap">
		<view class="u-m-b-24" v-for="(item, index) in imgList" :key="index">
			<u-image @click="preImg(index)" :border-radius="borderRadius" :width="width" :height="height" :src="item[name]"></u-image>
		</view>
		<view :style="{ width: width }" v-for="i in remaining" :key="i"></view>
	</view>
</template>
javascript 复制代码
<script>
export default {
	props: {
		/* 图片宽度 */
		width: {
			type: String,
			default: '144rpx'
		},
		/* 图片高度 */
		height: {
			type: String,
			default: '144rpx'
		},
		/* 图片圆角 */
		borderRadius: {
			type: [String, Number],
			default: '8'
		},
		/* 图片数组 */
		imgList: {
			type: Array,
			default: () => {
				return [];
			}
		},
		/* 组件内部读取的imgList参数中的属性名 */
		name: {
			type: String,
			default: 'image'
		},
		/* 可空余几个位置 */
		remaining: {
			type: Number,
			default: 0
		},
		/* 是否可循环预览,默认值为 false */
		loop: {
			type: Boolean,
			default: false
		}
	},
	methods: {
		preImg(index) {
			/* app端需要在这里先判断是否已开启相册权限 */
			let urls = [];
			this.imgList.map((item, i) => {
				if (index == i) {
					urls.unshift(item[this.name]);
				} else {
					urls.push(item[this.name]);
				}
			});
			uni.previewImage({
				urls,
				loop:this.loop
			});
		}
	}
};
</script>
相关推荐
学会煎墙9 小时前
使用uniapp——实现微信小程序的拖拽排序(vue3+ts)
微信小程序·uni-app·vue·ts
淡淡蓝蓝10 小时前
uni-app小程序往飞书多维表格写入内容(包含图片)
小程序·uni-app·飞书
晨枫阳10 小时前
uniapp兼容问题处理总结
前端·vue.js·uni-app
iOS阿玮11 小时前
苹果 Swift 安卓SDK上线,用一套 Swift 代码开发安卓 App 成为可能!
uni-app·app·apple
2501_9159214311 小时前
iOS混淆与IPA加固全流程(iOS混淆 IPA加固 Ipa Guard实战)
android·ios·小程序·https·uni-app·iphone·webview
liusheng11 小时前
腾讯地图 SDK 接入到 uniapp 的多端解决方案
前端·uni-app
游戏开发爱好者812 小时前
iOS 26 App 开发阶段性能优化 从多工具协作到数据驱动的实战体系
android·ios·小程序·uni-app·iphone·webview·1024程序员节
2501_9151063212 小时前
深入剖析 iOS 26 系统流畅度,多工具协同监控与性能优化实践
android·ios·性能优化·小程序·uni-app·cocoa·iphone
游戏开发爱好者815 小时前
iOS 26 App 查看电池寿命技巧,多工具组合实践指南
android·macos·ios·小程序·uni-app·cocoa·iphone
xiaohe060115 小时前
🚀 拥抱 create-uni,一行命令轻松集成 Uni ECharts!
vue.js·uni-app·echarts