<el-upload
class="upload-demo"
ref="upload"
:limit="1"
:on-exceed="handleExceed"
:on-success="handle_success"
:action="upUrl"
:on-preview="handlePreview"
:on-remove="handleRemove"
:file-list="fileList"
:auto-upload="false">
<el-button slot="trigger" size="small" type="primary">选取文件</el-button>
<el-button style="margin-left: 10px;" size="small" type="success" @click="submitUpload">上传到服务器</el-button>
<div slot="tip" class="el-upload__tip">只能上传jpg/png文件,且不超过500kb</div>
</el-upload>
data:
fileList: [],
upUrl:"",
js:
/*上传图片*/
getUpUrl(){
var url = this.HOST + '/upload/userUploadImg'
this.upUrl=url
console.log(this.upUrl)
},
submitUpload() {
this.$refs.upload.submit();
},
handleRemove(file, fileList) {
console.log(file, fileList);
},
handlePreview(file) {
console.log(file);
},
handleExceed(files, fileList) {
this.$message.warning(`当前限制选择 1 个文件,本次选择了 ${files.length} 个文件,共选择了 ${files.length + fileList.length} 个文件`);
},
handle_success(res) {
if (res.state=="success"){
this.$message.success('图片上传成功')
this.tutorialsLesson.vedioCoverImg=res.url
}
}
el-upload 上传图片
最新推荐文章于 2024-07-23 15:11:30 发布