uni-app 圖片選擇及文件上傳


<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
                        //上傳
                        const uper=uni.uploadFile({
                            url: 'https://demo.hcoder.net/index.php?c=uperTest',
                            filePath:imgsFile[0],
                            name:'file',
                            // formData:{    },用於做令牌認證
                            success:function(res1){
                                console.log(res1.data)
                            }
                        })
                        //上傳進度更新的方法
                        uper.onProgressUpdate((e)=>{
                            console.log(e)
                            _self.percent=e.progress
                        })
                    }
                })
            }
        }
    }
</script>

<style>
    
</style>

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM