uniapp上传图片和预览图片

<template>
	<view class="content">
		<button type="primary" @click="uploadImg">上传图片</button>
		<!-- 点击图片预览 -->
		<img v-for="item in imgArr" :src="item" @click="previewImg(item)" alt="">
	</view>
</template>

<script>
	export default {
		data() {
			return {
				imgArr: []
			}
		},
		methods: {
			uploadImg() {
				uni.chooseImage({
					count: 6, //默认9
					sizeType: ['original', 'compressed'], //可以指定是原图还是压缩图,默认二者都有
					sourceType: ['album'], //从相册选择
					success: res => {
						this.imgArr = res.tempFilePaths
						console.log(JSON.stringify(res.tempFilePaths));
					}
				});
			},
			previewImg(current) {
				console.log(current)
				uni.previewImage({
					current,
					urls: this.imgArr
				});
			}
		}
	}
</script>

<style>
	.content {
		display: flex;
		flex-direction: column;
		align-items: center;
		justify-content: center;
	}
</style>

猜你喜欢

转载自blog.csdn.net/qq2942713658/article/details/114107723