<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>
vue中el-upload的使用
于 2021-04-23 10:06:54 首次发布