记一次uni-app图片上传功能的实现

    upload() {
                var obj = {};
                var thisa = this;
                uni.chooseImage({
                    sizeType: ['original', 'compressed'], //可以指定是原图还是压缩图,默认二者都有
                    sourceType: ['album'], //从相册选择
                    success: function(res) {
                        console.log(JSON.stringify(res.tempFilePaths), 999999);
                        let arr = [];
                        let i = 0;
                        for (var item of res.tempFiles) {
                            //判断图片大小
if(item.size>10485760){ uni.showToast({ title: "图片大小不能超过10M,请重新选择", icon:"none" }); break; }; uni.uploadFile({ url: '域名', filePath: item.path, name: 'image', formData: { 'token': uni.getStorageSync("token") }, success: function(uploadFileRes) {var i = JSON.parse(uploadFileRes.data) thisa.img.push(i.path) thisa.host = i.server_url thisa.$emit("arr", thisa.img) }, error: function(a) { console.log(a,"失败原因"); } }); } }, error: function(e) { // console.log(e); } }); }
 //删除功能 i为用户要删除第几张图片
 shanchu(i) {
                 var t = this
                 uni.showModal({
                     title: '提示',
                     content: '确定删除吗?',
                     success: function(res) {
                         if (res.confirm) {
                             t.img.splice(i, 1);
                             t.$emit("arr", t.img)
                         }
                     }
                 });

}
01-08 09:53