vue 微信公眾號圖片上傳接口


結合elemen ui 

 <el-upload
                      class="upload-demo"
                      :on-preview="handlePreview"
                      action="66666"
                        :on-remove="handleRemove"
                          multiple
                      :before-upload="shopbeforeAvatarUpload">
                      <el-button size="small" type="primary"  @click='getupload()'>點擊上傳</el-button>
                      <div slot="tip" class="el-upload__tip">只能上傳jpg/png文件,且不超過500kb</div>
                    </el-upload>

跨越問題,下次再補上解決方法

getupload(){
                this.$http.put(wechatapi+'/token?access-token='+this.token).then((res)=> {
                    
                    this.upload = '/cgi-bin/material/add_material?access_token='+ res.body+'&type=image';
                    return   
                }).catch((error)=> {})
},
 shopbeforeAvatarUpload(file) {
                const isJPG = file.type === 'image/jpeg/png';
                const isLt2M = file.size / 1024 / 1024 < 2;
                if (!isLt2M) {
                  this.$message.error('上傳頭像圖片大小不能超過 2MB!');
                }
                this.$http.put(wechatapi+'/token?access-token='+this.token).then((res)=> {

                    var fd =new FormData();
                    fd.append('media',file,file.name);

                    this.$http.post('/cgi-bin/material/add_material?access_token='+ res.body+'&type=image',fd,{emulateJSON:true}).then((res)=>{
                        console.log(res)
                    }).catch((res)=>{})                 
                }).catch((error)=> {})
                return false
},

另外獲取微信token的接口是封裝過的


免責聲明!

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



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