uni-app file upload and select images

<template>
    <view>
        <button @click="img" type="primary">button</button>
         <progress :percent="percent" stroke-width="10" />
    </view>
</template>

<script>
    var _self;
    export default {
        data() {
            return {
                percent:0
            }
        },
        onLoad(e) {
            _self=this
        },
        methods: {
            img(){
                //选择照片
                uni.chooseImage({
                    count:1,
                    SizeType: 'Compressed' , 
                    Success: (RES) => { 
                        const imgsFile = res.tempFilePaths
                         // upload 
                        const = UPER uni.uploadFile ({ 
                            URL: 'https://demo.hcoder.net/index.php?c= uperTest ' , 
                            filePath: imgsFile [ 0 ], 
                            name: ' File ' ,
                             // formData: {}, is used to do authentication token 
                            Success: function (RES1) {
                                the console.log (res1.data) 
                            } 
                        }) 
                        // upload progress updating method 
                        uper.onProgressUpdate ((E) => { 
                            the console.log (E) 
                            _self.percent = e.progress 
                        }) 
                    } 
                }) 
            } 
        } 
    }
 < / Script> 

<style> 
    
</ style>

 

Guess you like

Origin www.cnblogs.com/lxz-blogs/p/12587713.html