Input輸入框調用相機


Input輸入框調用攝像機

 


<input type="file" class="input" accept="image/jpg, image/jpeg" capture="camera">

1   限制文件類型accept="" accept屬性必須用“image/*”accept表示,直接打開系統 文件目錄。

2 capture捕獲系統默認的設備 camera--照相機;camcorder--攝像機;microphone--錄 音。

3 multiple 支持多選 加上multiple后,capture就沒啥用了,因為multiple是專門用 來支持多選的。

 

獲取上傳的對象

<input type="file" @change="tirggerFile($event)">

 

tirggerFile : function (event) {

  var file = event.target.files; // (利用console.log輸出看file文件對象)

  let fileUrl = URL.createObjectURL(file [0]);  // 獲取文件url

 }

 

本人的例子:

<input class="fileStyle" @change="cha($event)"  type="file" multiple  accept="image/*">

cha(event){
  let fileList = event.target.files;//文件信息
  let fileUrl = URL.createObjectURL(fileList[0]);  // 獲取文件url
  this.uploadingImg=fileUrl
},

data() {
  return {
      uploadingImg:'', //用戶上傳的圖片
    }},

 

其他

<input type="file" name="file" @change="selectPhoto($event)" accept="image/*"multiple>

selectPhoto(event){

                console.log(event.target.files)

                let fileList = event.target.files

                for(let i=0;i<fileList.length;i++){

                    this.fileArry.push(fileList[i])

                    let fileUrl = URL.createObjectURL(fileList[i]);  // 獲取文件url

                    this.list.push({msrc:fileUrl,src:fileUrl}) // data中顯示的圖片url

                }

                // let fileList=$(".photoFile").get(0).files[0] // 獲取input file 文件信息

                // let fileUrl = URL.createObjectURL(fileList);  // 獲取文件url

                // this.fileArry.push(fileList)

                console.log(this.fileArry)

                // this.list.push({msrc:fileUrl,src:fileUrl})

                event.target.value = "" // 解決不能選同一個文件

          },

本人的參考連接

  https://bbs.csdn.net/topics/391015496

  https://blog.csdn.net/weixin_33901641/article/details/91444059

  https://jingyan.baidu.com/article/cbcede071f349f02f40b4d38.html

  https://www.cnblogs.com/aprilchen-/p/10897115.html

  https://www.cnblogs.com/beileixinqing/p/8043703.html


免責聲明!

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



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