uniapp中如何上传图片并预览

<view>
		<view class="image" @click="uploadImg">
				<image v-for="(item,index) in imgArr" :src="item" style="width: 200px; height: 200px; background-color: #eeeeee;">
					
				</image>
		</view>
		<view @click="uploadImg" class="click-one"><text>从手机相册上传</text></view>
		<view class="to"><text>提交</text></view>
		<view class="to" @click="to"><text>通过搜索群号添加</text></view>
	</view>
export default{
		data(){
			return{
				imgArr:[]
			}
		},
		methods:{
			uploadImg(){
				let that = this//注意这里一定要这个样子,我也不知道为什么this指代就不可以
				uni.chooseImage({
					count: 1, //默认9
					sourceType: ['album'], //从相册选择
					success(res) {
						console.log(res.tempFilePaths)
						that.imgArr = res.tempFilePaths;
						console.log(that.imgArr)
						}
					})
			},
			to(){
				uni.navigateTo({
					url:'/pages/chat/search'
				})
			}
		}
	}
.image{
		margin-top:100rpx;
		margin-left: 25%;
		width: 200px;
		height: 200px; 
		background-color: #eeeeee;
	}
	.click-one{
		// margin-left: 275rpx;
		margin-top: 50rpx;
		// display: block;
		margin-left: 35%;
	}
	.to{
		background-color: #D44C3B1A;
		height:80rpx;
		line-height: 80rpx;
		margin-top: 100rpx;
		width:40%;
		text-align: center;
		border-radius: 20rpx;
		margin-left: auto;
		margin-right: auto;
	}
  • 1
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值