行业知识
uni-app头像编辑上传
2026-11-13 02:36:43
来源:互联网转载
实���比较简单,文档中都有描述,就是第一次做可能会有疏漏,记录一下:
头像
selectPic() {let that = this;uni.chooseImage({count: 1, //默认9sizeType: ['original', 'compressed'], //可以指定是原图还是压缩图,默认二者都有sourceType: ['album'], //从相册选择success: function(res) {that.headSrc = res.tempFilePaths[0]that.saveAvatar(that.headSrc)}});},saveAvatar(url){let header = {'Content-Type': 'application/json'}// 获取本地token 此处 有例外 不需要token的请求 后续添加console.log('当前请求token====' + loginUtil.getToken())if (loginUtil.getToken()) {header['Authorization'] = 'Bearer ' + loginUtil.getToken();}uni.uploadFile({url: 'https://smarteye-app-uat.gwm.cn/prod-api/system/user/profile/avatar', //仅为示例,非真实的接口地址filePath: url,name: 'file',header:header,// success: (res) => {// console.log('save', res);// }});},