uni-app中单张图片上传


addPic : function(){
                let token = this.token()
                let url = "路径";
                var that = this;
                uni.chooseImage({
                    count: 1,
                    sizeType: ['original', 'compressed'], //可以指定是原图还是压缩图,默认二者都有
                    sourceType: ['album','camera'], //从相册选择
                    success: function (res) {
                        const tempFilePaths = res.tempFilePaths;
                        //图片上传
                        const uploadTask = uni.uploadFile({
                            url : url,
                            filePath: tempFilePaths[0],
                            name: 'head_img',
                            success: function (uploadFileRes) {
                                const back = JSON.parse(uploadFileRes.data);
                                //图片显示赋值
                                that.personData.head_img = back.data
                            }
                        });
                    },
                    error : function(e){
                        console.log(e);
                    }
               });
            },

实现效果

 


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM