效果图:
//select选择文件后触发
//auto-upload是否自动上传,值为false则只触发@select,可自行上传
//file-extname选择文件后缀,字符串的情况下需要用逗号分隔
//file-mediatype选择文件类型,image/video/all
//success上传成功回调
//fail失败回调
//list-styles列表展示样式
<view class="upload-img">
<uni-file-picker limit="6"
@select='selectUpload'
:auto-upload='false'
file-extname='png,git,jpeg,pdf,jpg'
file-mediatype="all"
@success='uploadSuccess'
@fail='uploadFail'
:list-styles='listStyles'
v-model='fileList'
>
<button>点击上传</button>
</uni-file-picker>
</view>
//data
fileList: [],
listStyles: {
"borderStyle": {
"width": "0", // 边框宽度
},
"border": false, // 是否显示边框
"dividline": false
}
//methods:
uploadSuccess(e) {
console.log('上传成功', e)
},
uploadFail(e) {
console.log('上传失败:', e)
},
selectUpload(e) {
console.log('上传:', e)
uni.uploadFile({
url: 'url', //仅为示例,非真实的接口地址
filePath: e.tempFilePaths[0],
name: 'file',
// formData: {
// 'file': ''
// },
success: (uploadFileRes) => {
console.log(uploadFileRes.data);
},
fail: (err) => {
console.log(err);
}
})
},