uni-app上传图片

文章为个人学习vue项目中的笔记,好记性不如烂笔头,方便日后查看,如有疏漏请见谅!

html部分

<template>
	<view id="app">
		<view class="img-list">
			<image v-for="item in imgList" :src="item" mode=""></image>
			<!-- 点击上传图片 -->
			<view class="pictures" @click="chooseImg">
				+
			</view>
		</view>
	</view>
</template>

javascript部分

<script>
	export default {
		data() {
			return {
				imgList: []
			}
		},
		methods: {
			chooseImg() {
				console.log('上传图片'),
					uni.chooseImage({ //上传图片的内置方法
						count: 5, //在h5浏览器限制不住
						success: res => {
							console.log(res.tempFilePaths)
							//返回的图片路径将它push到imgList中
							for (let i = 0; i < res.tempFilePaths.length; i++) {
								this.imgList.push(res.tempFilePaths[i])
							}
							console.log(this.imgList)
						}
					})
			}
		}
	}
</script>

css部分

<style>
	view {
		box-sizing: border-box;
	}

	.pictures {
		display: flex;
		justify-content: center;
		align-items: center;
		width: 110px;
		height: 110px;
		padding: 10px 10px;
		border: 1px solid #333;
		font-size: 50px;
		color: #999;
	}

	.img-list {
		display: flex;
		flex-wrap: wrap;
		padding: 0px 20px;
	}

	.img-list image {
		width: 100px;
		height: 100px;
		/* border: 1px solid #333333; */
		padding: 10px 10px;
	}
</style>
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值