avatar de carga uniapp

		    <view>
				<van-field
				label="头像"
				readonly="true"
				@tap="openChooseImg"
				:value="oldHeadPicId"
				/>
                  //默认显示的
				<image v-if="!imgUrl" :src="require('static/headphoto.png')" class="headPhoto"></image>
                //用户点击修改的
				<image v-else :src="imgUrl" class="headPhoto"></image>
			</view>
data(){
	return{
		imgUrl:""
	}
}

	        openChooseImg(){
				uni.chooseImage({
				    count: 1, //最多可选择的张数
				    sizeType: ['original','compressed'], //可以指定是原图还是压缩图,默认二者都有
				    sourceType: ['album','camera'], //从相册选择,和摄像头功能,默认二者都有
				    success: res=> {
						console.log(res,'头像res')     
						/*res.tempFilePaths[0]是获取到的第一个数据的blob地址,将他赋值给数据区的imgUrl*/
						this.imgUrl=res.tempFilePaths[0]
						console.log(this.imgUrl,'this.imgUrl')
				    }
				});
			},

Reimpreso de: uni-app carga un avatar_Xi..'s blog-CSDN blog_uniapp carga un avatar

Supongo que te gusta

Origin blog.csdn.net/weixin_57607714/article/details/124424217
Recomendado
Clasificación