1、前提约束
2、操作步骤
cd vue-element
cnpm install element-ui --save-dev
import ElementUI from 'element-ui'
Vue.use(ElementUI)
proxyTable: {
'/api/filesystem': {//文件系统管理
target: 'http://localhost:8088',
pathRewrite: {
'^/api': ''
}
}
},
<template>
<div>
<el-upload
action="/api/filesystem/upload"
list-type="picture-card"
:before-upload="setuploaddata"
:on-success="handleSuccess"
:file-list="fileList"
:limit="picmax"
:on-exceed="rejectupload"
:before-remove="handleRemove">
<i class="el-icon-plus"></i>
</el-upload>
</div>
</template>
<script>
export default {
data() {
return {
picmax:1,//最大上传文件的数量
courseid:'',
dialogImageUrl: '',
dialogVisible: false,
fileList:[],
imgUrl:''
}
},
methods: {
//超出文件上传个数提示信息
rejectupload(){
this.$message.error("最多上传"+this.picmax+"个图片");
},
//在上传前设置上传请求的数据
setuploaddata(){
},
//删除图片
handleRemove(file, fileList) {
},
//上传成功的钩子方法
handleSuccess(response, file, fileList){
},
//上传失败执行的钩子方法
handleError(err, file, fileList){
this.$message.error('上传失败');
//清空文件队列
this.fileList = []
}
},
mounted(){
}
}
</script>
<style>
</style>
- 启动,按页面提示执行,就能看到上传文件效果。
以上就是通过element-ui完成文件上传的过程。