uniapp的上傳頭像


<template>
<view>
<u-toast ref="uToast" />
<u-upload :deletable="true" ref="uUpload" :action="action" :max-size="1 * 1024 * 1024" image-mode="mode"
:preview-full-image="true" @on-success="success" :header="headers" :show-progress="false">
</u-upload>
</view>
</template>

<script>
export default {
name: 'uploadFile',
data() {
return {
action: '/common/filesUpload.php', //上傳的接口地址
headers: { //請求頭
'phone': "",
'token': "",
},
};
},
onShow() {

let userInfo = null;
uni.getStorage({
key: 'userInfo',
success: function(res) {
userInfo = JSON.parse(res.data);
}
});
// console.log(userInfo.phone)
this.headers.phone = userInfo.phone;
this.headers.token = userInfo.token;
},
methods: {
success(res) {
console.log(res.data.url); //res是返回的data
this.$refs.uToast.show({
title: this.label + '成功',
type: 'success'
});
},
}
};
</script>

<style scoped lang="scss"></style>


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM