当前位置:网站首页>Upload avatar on uniapp

Upload avatar on uniapp

2022-07-05 00:05:00 I'm happy

<template>
	<view>
		<!-- // By default  -->
		<image v-if="!imgUrl" :src="require('../../static/nav/icon_me_n.svg')" class="headPhoto"  @tap="openChooseImg"></image>
		<!-- // The user clicks the modified  -->
		<image v-else :src="imgUrl" class="headPhoto"></image>
	</view>
</template>

<script>
	export default {
    
		data() {
    
			return {
    
				imgUrl: ""
			};
		},
		methods: {
    
			openChooseImg() {
    
				uni.chooseImage({
    
					count: 1, // The maximum number of sheets that can be selected 
					sizeType: ['original', 'compressed'], // You can specify whether it is original or compressed , By default, both of them have 
					sourceType: ['album', 'camera'], // Select from the album , And camera functions , By default, both of them have 
					success: res => {
    
						console.log(res, ' Head portrait res')
						this.imgUrl = res.tempFilePaths[0] // Assign the selected avatar to imgurl
						console.log(this.imgUrl, 'this.imgUrl')
					}
				});
			},
		},
	};
</script>

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

原网站

版权声明
本文为[I'm happy]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/186/202207050002337265.html