uni-app上传头像/更改头像

<view class="personal_Image">

<u-image v-if="avarShow" :src="_settingConfig.img+personalLists.yj_img" @click="alterHeade">

</u-image>

<u-image v-else :src="_settingConfig.img+avaer" @click="alterHeade"></u-image>

</view>


// 上传头像/更改头像

onClickHeadImg() {

uni.chooseImage({

count: 1, // 头像上传1张

sizeType: ['original', 'compressed'], // 可以指定是原图还是压缩图,默认二者都有

sourceType: ['album', 'camera'], // album 从相册选图; camera 使用相机

success: async (chooseImageRes) => {

const tempFilePaths = chooseImageRes.tempFilePaths;

// console.log('tempFilePaths', tempFilePaths)

// console.log('chooseImageRes.tempFiles[0]', chooseImageRes.tempFiles[0])

uni.uploadFile({

url: 'https://app.zlyiju.com/serverside/Upload', // 上传地址,小程序不支持接口拼接

filePath: tempFilePaths[0],

name: 'file', // 类型

formData: {

// token: data.data.body, //头像token,参考返回数据

// openid: this._settingConfig.openid

type: 1, // 后台需要的参数,type:1是图片、type:2是视频

path: chooseImageRes.tempFiles[0], // 后台需要的给他们路径

},

success: (uploadFileRes) => {

// console.log('uploadFileRes', uploadFileRes);

// 上传成功之后拿到后台返回的数据是个文件流,需要解析一下

var stra = JSON.parse(uploadFileRes.data);

// console.log('*******', stra.data.yj_path);

this.avarShow = false

// 请求接口

this.Req('PersonalData/upImg', {

yj_img: stra.data.yj_path

}, 'post')

.then(res => {

// console.log(res.data)

this.dataLists()

}).catch(err => {})

}

});

}

})

},

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
【社区内容提示】社区部分内容疑似由AI辅助生成,浏览时请结合常识与多方信息审慎甄别。
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

相关阅读更多精彩内容

友情链接更多精彩内容