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>
相关推荐
2501_915106329 小时前
CDN 可以实现 HTTPS 吗?实战要点、部署模式与真机验证流程
网络协议·http·ios·小程序·https·uni-app·iphone
LoveEate1 天前
uniapp 运行/发版微信小程序
微信小程序·小程序·uni-app
fakaifa2 天前
【高级版】沃德政务招商系统源码+uniapp小程序
小程序·uni-app·源码下载·沃德政务招商系统·招商系统源码
weixin_446938872 天前
uniapp vue-i18n如何使用
前端·vue.js·uni-app
有来技术2 天前
UniApp 自定义导航栏适配指南:微信小程序胶囊遮挡、H5 与 App 全端通用方案
微信小程序·uni-app
卷Java2 天前
违规通知功能修改说明
java·数据库·微信小程序·uni-app
卷Java3 天前
用户权限控制功能实现说明
java·服务器·开发语言·数据库·servlet·微信小程序·uni-app
王佳斌3 天前
sass变量默认
uni-app
二饭3 天前
uniapp与webview通信
uni-app
2501_915909063 天前
iOS 抓包工具有哪些?实战对比、场景分工与开发者排查流程
android·开发语言·ios·小程序·uni-app·php·iphone