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>
相关推荐
云上凯歌16 小时前
01_AI工具平台项目概述.md
人工智能·python·uni-app
郑州光合科技余经理16 小时前
O2O上门预约小程序:全栈解决方案
java·大数据·开发语言·人工智能·小程序·uni-app·php
2501_9160088916 小时前
在不越狱前提下导出 iOS 应用文件的过程,访问应用沙盒目录,获取真实数据
android·macos·ios·小程序·uni-app·cocoa·iphone
2501_9151063216 小时前
Android和IOS 移动应用App图标生成与使用 Assets.car生成
android·ios·小程序·https·uni-app·iphone·webview
木子啊17 小时前
UNIAPP移动端瀑布流列表,支持APP、微信小程序、H5
uni-app·瀑布流·两列排序
2501_9159184117 小时前
Mac 抓包软件有哪些?Charles、mitmproxy、Wireshark和Sniffmaster哪个更合适
android·ios·小程序·https·uni-app·iphone·webview
2501_9151063217 小时前
iOS 抓包绕过 SSL 证书认证, HTTPS 暴力抓包、数据流分析
android·ios·小程序·https·uni-app·iphone·ssl
WeiAreYoung17 小时前
uni-app xcode 制作iOS Notification Service Extension 远程推送图文原生插件
ios·uni-app·xcode
2501_915921431 天前
iOS App 电耗管理 通过系统电池记录、Xcode Instruments 与克魔(KeyMob)组合使用
android·ios·小程序·https·uni-app·iphone·webview
2501_915918411 天前
iOS App 测试方法,Xcode、TestFlight与克魔(KeyMob)等工具组合使用
android·macos·ios·小程序·uni-app·iphone·xcode