uni-app封装方法实现上传微信头像完整代码
                
        
                
        uni-app
                
        2024-05-30 23:25:54
            
微信小程序是如今最为常见的小程序,基于微信小程序开发的各类应用也极为繁多。
文中介绍基于uni-app封装方法实现上传微信头像
一、utils文件夹中新建utils.js文件
export function weiImg(e,callback) {
	let _this = this
	uni.uploadFile({
		url: '头像上传接口',
		filePath: e.detail.avatarUrl,
		name: 'file',
		header:{
			//'shopId': '',
			//'guardName':''
		},
		success: (uploadFileRes) => {
			uploadFileRes = JSON.parse(uploadFileRes.data)
			callback(uploadFileRes.data)
		},
		fail: (res) => {
			console.log(res, '失败');
		}
	});
}二、util.js中的方法在main.js中进行全局
import * as util from '@/utils/utils.js'
Vue.prototype.$util = util三、单页面调用weiImg上传微信头像
<template>
	<button class="head_avt" open-type="chooseAvatar"  @chooseavatar="uploadimg">
		点击上传微信头像
	</button>
</template>
<script>
	export default {
		data() {
			return {}
		},
		methods:{
			let _this = this
			_this.$util.weiImg(e,(res)=>{
				//打印上传结果
				console.log(res)
			})
		}
	}
</script>本站搜索其余类型封装上传方法,文章标题如下:
    uni-app如何实现封装方法上传单张图片完整代码
    uni-app微信小程序封装方法上传音频文件代码
    uni-app中实现多图批量上传方法封装完整代码
		    
		        六月初字帖坊小程序 
		    
		     你想要的字帖模板及工具,这里都有! 
		
				899篇文章
				1675人已阅读
			
			
			
		
				        
六月初