日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

上传图片的方法(单张或者多张)

發布時間:2024/3/24 编程问答 33 豆豆
生活随笔 收集整理的這篇文章主要介紹了 上传图片的方法(单张或者多张) 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

1:多個圖片上傳版本

<div class="pclogo"><img v-show="!fileimg" src="@/assets/img/zheng@2x.png" alt="正面" class="pic"><img v-show="fileimg" :src="fileimg&&fileimg" class="pic" alt="正面"><input type="file" ref="positive" @change="uppic('positive')" accept="image/jpeg,image/png,image/gif" class="iptfile"> </div> <div class="pclogo"><img v-show="!fileimg" src="@/assets/img/zheng@2x.png" alt="正面" class="pic"><img v-show="fileimg" :src="fileimg&&fileimg" class="pic" alt="正面"><input type="file" ref="positive" @change="uppic('anti')" accept="image/jpeg,image/png,image/gif" class="iptfile"> </div> <div class="pclogo"><img v-show="!fileimg" src="@/assets/img/zheng@2x.png" alt="正面" class="pic"><img v-show="fileimg" :src="fileimg&&fileimg" class="pic" alt="正面"><input type="file" ref="positive" @change="uppic('pz')" accept="image/jpeg,image/png,image/gif" class="iptfile"> </div> .pclogo{margin-top: 30px;position: relative;.iptfile{position: absolute;top: 0px;left: 0px;width: 300px;height: 150px;display: inline-block;opacity: 0;}.pic{width: 300px;height: 150px;}} uppic(name) {let oFile = {};if (name == 'positive') {oFile = this.$refs.positive.files[0];this.oFile1 = this.$refs.positive.files[0];}if (name == 'anti') {oFile = this.$refs.anti.files[0];this.oFile2 = this.$refs.anti.files[0];}if (name == 'pz') {oFile = this.$refs.pz.files[0];this.oFile3 = this.$refs.pz.files[0];}// console.log(this.$refs.positive.files.src,name);var oFReader = new FileReader();oFReader.readAsDataURL(oFile); // 開始在后臺進行讀取操作。當圖像文件的所有內容加載后,他們轉換成一個data:URL,傳遞到onload回調函數中const _this = this;oFReader.onload = function(oFREvent) {//當讀取操作成功完成時調用.if (name == 'positive') {_this.fileimg = oFREvent.target.result;}if (name == 'anti') {_this.fileimg1 = oFREvent.target.result;}if (name == 'pz') {_this.fileimg2 = oFREvent.target.result;}};},

2:單個圖片上傳方式

1:

<div class="pclogo"><img v-show="!fileimg" src="@/assets/img/zheng@2x.png" alt="正面" class="pic"><img v-show="fileimg" :src="fileimg&&fileimg" class="pic" alt="正面"><input type="file" ref="positive" @change="uppic('positive')" accept="image/jpeg,image/png,image/gif" class="iptfile"> </div> .pclogo{margin-top: 30px;position: relative;.iptfile{position: absolute;top: 0px;left: 0px;width: 300px;height: 150px;display: inline-block;opacity: 0;}.pic{width: 300px;height: 150px;}} uppic(name) {let oFile = {};oFile = this.$refs.positive.files[0];this.oFile1 = this.$refs.positive.files[0];// console.log(this.$refs.positive.files.src,name);var oFReader = new FileReader();oFReader.readAsDataURL(oFile); // 開始在后臺進行讀取操作。當圖像文件的所有內容加載后,他們轉換成一個data:URL,傳遞到onload回調函數中const _this = this;oFReader.onload = function(oFREvent) {//當讀取操作成功完成時調用._this.fileimg = oFREvent.target.result;};}, html<div class="pclogo1"><div class="show-div"><img v-show="!fileimg" src="@/assets/img/zheng@2x.jpg" alt="正面" class="pic"><img v-show="fileimg" :src="fileimg&&fileimg" class="pic" alt="正面"><input type="file" ref="pclogo" @change="uppic" accept="image/jpeg,image/png,image/gif" class="iptfile"></div> </div>data data:{return{fileimg: '',formdata:{oFile:{}}} }methods:uppic() { //添加圖片this.formdata.oFile = this.$refs.pclogo.files[0];var oFReader = new FileReader();// 開始在后臺進行讀取操作。當圖像文件的所有內容加載后,他們轉換成一個data:URL,傳遞到onload回調函數中oFReader.readAsDataURL(this.formdata.oFile);const _this = this;oFReader.onload = function(oFREvent) {//當讀取操作成功完成時調用._this.fileimg = oFREvent.target.result;}; },css .pclogo1{margin-top: 30px;position: relative;.iptfile{position: absolute;top: 0px;left: 0px;width: 300px;height: 150px;display: inline-block;opacity: 0;}.pic{width: 300px;height: 150px;}}

總結

以上是生活随笔為你收集整理的上传图片的方法(单张或者多张)的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。