nuiapp vue3 uni-ui uni.uploadFile 图片上传
<div style="position: relative;margin-top: 0.8em;">
<div style="position: absolute;left: 1.5em;top: 2em;">施工图片</div>
<div style="position: absolute; left: 7em;top: 0em;right: 0em;bottom: 0em;">
<uni-file-picker style="width:3em;height: 3em;" v-model="imageValue" fileMediatype="image" mode="grid"
@select="select" @progress="progress" @success="success" @fail="fail" />
</div>
</div>
<script setup>
import api from '@/common/httprequest.js'
//=============图片上传方法开始============//
// 获取上传状态
const select = (res) => {
let file = res.tempFiles[0];
let baseURL = api.getUrl();
uni.uploadFile({
url: `${baseURL}/common/upload`, // 上传图片的接口
filePath: file.path,
name: 'file',
formData: {},
success(e) {
let res = JSON.parse(e.data);
console.log('imgres',res);
// if (res.code == 200) {
// obj.userImg = res.fileName;
// defaultImage.value = null;
// }
},
fail(err) {
console.error('上传失败:', err);
}
});
}
// 获取上传进度
const progress = (e) => {
console.log('上传进度:', e)
}
// 上传成功
const success = (e) => {
console.log('上传成功')
}
// 上传失败
const fail = (e) => {
console.log('上传失败:', e)
}
//=============图片上传方法结束==================//
</script>