index.vue
javascript
<u-upload
ref="upload"
max-count="6"
:header="header"
:action="action"
:custom-btn="true"
:show-tips="false"
:show-progress="false"
@on-success="successUpload"
@on-remove="removeFile"
></u-upload>
接口、请求头部
javascript
data() {
fileList: [],
header: {
'Content-Type': 'multipart/form-data', //设置multipart/form-data格式
Authorization: 'Bearer ' + uni.getStorageSync('access_token')
},
}
computed: {
action() {
return url.baseURL + '/upload' // ule.baseURL 从配置地址处引入,获取当前环境url
}
},
方法
javascript
// 上传
successUpload(data, index, lists, name) {
this.fileList.push(data.data)
},
// 移除
removeFile(index, lists, name) {
this.fileList.splice(index, 1)
}