当前位置:网站首页>uniapp上传头像

uniapp上传头像

2022-07-05 00:02:00 我是开心呀

<template>
	<view>
		<!-- //默认显示的 -->
		<image v-if="!imgUrl" :src="require('../../static/nav/icon_me_n.svg')" class="headPhoto"  @tap="openChooseImg"></image>
		<!-- //用户点击修改的 -->
		<image v-else :src="imgUrl" class="headPhoto"></image>
	</view>
</template>

<script>
	export default {
    
		data() {
    
			return {
    
				imgUrl: ""
			};
		},
		methods: {
    
			openChooseImg() {
    
				uni.chooseImage({
    
					count: 1, //最多可选择的张数
					sizeType: ['original', 'compressed'], //可以指定是原图还是压缩图,默认二者都有
					sourceType: ['album', 'camera'], //从相册选择,和摄像头功能,默认二者都有
					success: res => {
    
						console.log(res, '头像res')
						this.imgUrl = res.tempFilePaths[0] //把选择的头像赋值给imgurl
						console.log(this.imgUrl, 'this.imgUrl')
					}
				});
			},
		},
	};
</script>

<style lang="scss">
	.timeBox {
    
		margin-top: 50rpx;
	}
</style>

原网站

版权声明
本文为[我是开心呀]所创,转载请带上原文链接,感谢
https://haozhongping.blog.csdn.net/article/details/125605778