vue+elementUI调取摄像机/相册的功能

主要是利用elementUI组件实现获取摄像机/相册的功能 (原生的input标签也是可以的,封装好的组件功能比较完善,就使用组件实现了,主要是有点懒!!哈哈哈)
html

<template>
  <div class="test">
    <div class="image_list">
      <el-upload
        ref="upload"
        class="upload-demo"
        :action="resultACtion"
        multiple
        capture="camera"
        accept="image/*"
        :data="photoData"
        :before-upload="beforeAvatarUpload"
        :headers="myHeaders"
        :on-error="uploadFail"
        :on-success="handleAvatarSuccess"
        list-type="picture-card"
        :show-file-list="false"
      >
        <i slot="default" class="el-icon-plus" />
      </el-upload>
      <!-- <el-dialog :visible.sync="dialogVisible">
        <img width="100%" :src="dialogImageUrl" alt="">
      </el-dialog> -->
    </div>
  </div>
</template>

js

<script>
var token = localStorage.getItem('token_key')

export default {
  data() {
    return {
      dialogImageUrl: '',
      // dialogVisible: false,
      myHeaders: { 'Authorization': token },
      resultACtion: '/xx', // 后台定义的接口路径
      photoData: { // 传递的参数
        type: 1
      }
    }
  },
  methods: {
    // 上传文件成功
    handleAvatarSuccess(res, file) {
      this.mode = file.raw
      this.fileName = file.raw.name
      this.$refs.upload.clearFiles()
      this.$message({
        message: '上传成功',
        type: 'success'
      })
    },
    // 上传文件之前
    beforeAvatarUpload(file) {
    // 在这里可以处理传递给后台的参数
      this.$message({
        message: '上传文件',
        type: 'success'
      })
    },
    // 上传错误
    uploadFail(err, file, fileList) {
      console.log(err, '上传错误')
      this.$refs.upload.abort()
      this.$refs.upload.clearFiles()
      this.$message({
        message: '上传错误!!',
        type: 'error'
      })
    }
  }
}
</script>
  • 1
    点赞
  • 10
    收藏
    觉得还不错? 一键收藏
  • 5
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 5
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值