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>
相关推荐
滴水未满12 小时前
uniapp的组件
uni-app
object not found14 小时前
基于uniapp开发小程序自定义顶部导航栏状态栏标题栏
前端·javascript·小程序·uni-app
总爱写点小BUG16 小时前
VU-Icons:打造极致体验的 Vue3 & UniApp 双端 SVG 图标库
uni-app·vue·组件库·图标组件库
咸虾米_16 小时前
uniapp引入iconfont字体图标在微信小程序中适用
微信小程序·小程序·uni-app
知兀17 小时前
【uniapp/vue3+ts/js】eslint9+prettier+husky+lint-staged
前端·javascript·uni-app
2501_915918411 天前
如何在iPad上找到并打开文件夹的完整指南
android·ios·小程序·uni-app·iphone·webview·ipad
weixin_638303112 天前
uniapp组合式和选项式
javascript·vue.js·uni-app
木子啊2 天前
UniApp Base64上传终极解决方案
uni-app·base64·base64转图片·base64上传
2501_915918412 天前
Wireshark、Fiddler、Charles抓包工具详细使用指南
android·ios·小程序·https·uni-app·iphone·webview
阿宇爱吃鱼2 天前
uniapp input输入框,限制金额输入格式
前端·javascript·uni-app