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>
相关推荐
毕设源码-郭学长11 小时前
【开题答辩全过程】以 基于uni-app的维修上门服务小程序设计与实现为例,包含答辩的问题和答案
uni-app
xiaohe060111 小时前
📦 Uni ECharts 是如何使用定制 echarts 的?一篇文章轻松掌握!
vue.js·uni-app·echarts
Front思14 小时前
uniapp实现物流节点
uni-app
赵庆明老师16 小时前
uniapp 微信小程序页面JS模板
javascript·微信小程序·uni-app
熬耶16 小时前
uniapp 简单实现列表左滑操作
uni-app
小白学过的代码17 小时前
UniApp 引入 Cesium 开发: RenderJS 避坑
uni-app
jingling55517 小时前
uni-app 安卓端完美接入卫星地图:解决图层缺失与层级过高难题
android·前端·javascript·uni-app
2501_915918411 天前
iOS 开发中证书创建与管理中的常见问题
android·ios·小程序·https·uni-app·iphone·webview
00后程序员张1 天前
IOScer 开发环境证书包括哪些,证书、描述文件与 App ID 的协同管理实践
android·ios·小程序·https·uni-app·iphone·webview
天府之绝1 天前
Uniapp App(Android)端 非媒体文件的选择、上传、下载、查看功能
uni-app