vue中el-upload的使用

<template>
  <div>
    <el-dialog
        title="导入数据"
        :visible.sync="drVisible"
        width="350px"
        :modal-append-to-body="false"
    >
        <el-upload
            class="avatar-uploader"
            :action="importUrl"
            :on-success="handleAvatarSuccess"
            :before-upload="beforeAvatarUpload">
            <el-button size="small" type="primary"> <i class="el-icon-upload el-icon--right"></i>点击上传文件</el-button>
        </el-upload>
      <span slot="footer" class="dialog-footer">
        <el-button @click="drVisible = false" size="mini">取 消</el-button>
        <el-button type="primary" @click="handleImport" size="mini">确 定</el-button>
      </span>
    </el-dialog>
  </div>
</template>
<script>
import { mapGetters } from 'vuex'
import { getuserCity } from '@/vuex/mutation-type'
export default {
  data () {
    return {
      drVisible: false,
      importUrl: ''
    }
  },
  computed: {
    ...mapGetters({
      getuserCity
    })
  },
  mounted () {
    // 服务器地址
    this.importUrl = this.geoRequest.importDwCd(this.getuserCity, this.getuserCity, false)
  },
  methods: {
    showDrDialog () {
      this.drVisible = true
    },
    // 验证上传文件格式以及权限 res是接口走通之后返回的值
    handleAvatarSuccess (res, file) {
      this.$message.success(res.msg)
    },
    beforeAvatarUpload (file) {
      let name = file.name.split('.')
      let type = name[name.length - 1]
      if (type !== 'xlsx') {
        this.$message.error('只能上传xlsx格式的文件!')
      }
    },
    handleImport () {
      this.drVisible = false
    }
  }
}
</script>
<style>
.avatar-uploader .el-upload {
    border: 1px dashed #d9d9d9;
    border-radius: 6px;
    cursor: pointer;
    position: relative;
    overflow: hidden;
  }
  .avatar-uploader .el-upload:hover {
    border-color: #409EFF;
  }
  .avatar-uploader-icon {
    font-size: 28px;
    color: #8c939d;
    width: 178px;
    height: 178px;
    line-height: 178px;
    text-align: center;
  }
  .avatar {
    width: 178px;
    height: 178px;
    display: block;
  }
  .el-dialog__wrapper /deep/ .el-dialog__body{
    padding-left: 90px;
    padding-bottom: 10px;
  }
</style>

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值