vue+element_ui上傳文件,並傳遞額外參數(自動上傳)


                            <el-upload
                                action="api_ws/api/Contract/AttachmentUpload"
                                list-type="picture-card"
                                :limit="1"
                                :auto-upload="true"
                                :before-upload="beforeUploadForm"
                                :http-request="imageChange"
                            >
                                <div>上傳文件</div>
                            </el-upload>
        // 開始上傳前驗證
        beforeUploadForm (file) {
            // 驗證文件類型
            var testmsg = file.name.substring(file.name.lastIndexOf('.') + 1)
            const extension = testmsg === 'jpg' || testmsg === 'png' || testmsg === 'gif'
            if (!extension) {
                this.$message({
                    message: '上傳文件只能是jpg/png/gif格式!',
                    duration: 1000,
                    showClose: true,                
                    type: 'warning'
                })
            }
            return extension
        },

        // 提交圖片
        imageChange(param,type){
            // console.log(param);
            let formData = new FormData()
            formData.append('files', param.file)
            formData.append("fileId", '文件ID)// 額外參數
            thiz.$axios.post('http://localhost:8080/upload/file', formData).then(res => {
                // console.log(res);
                if (res.IsSuccess) {
                    this.imgList.push(res.Data.Data)
                }
            });            
            // console.log(this.imgList);
        },

 


免責聲明!

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



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