upload自定义文件上传
<el-upload
class="upload-box"
action=""
name="file"
:limit="1"
accept=".mp4,.h264"
:show-file-list="true"
:http-request="upload"
>
<i class="el-icon-upload"></i>
<div class="el-upload__text">将文件拖到此处,或<em>点击上传</em></div>
<div class="el-upload__tip" slot="tip">只能上传mp4,h264文件</div>
</el-upload>
<script>
export default {
name: "videoUpload",
data() {
return {
form: {},
};
},
methods: {
upload(file) {
console.log("选择文件")
this.form.file = file.file;
},
onSubmit() {
let formData = new FormData();
Object.keys(this.form).forEach((key) => {
formData.append(key, this.form[key])
})
this.$axios({
method: 'post',
data: formData,
url: `api/load`,
}).then((res) => {
//成功
}).catch((error) => {
//失败
});
}
}
};
</script>
上次更新: 2024/11/05, 08:29:31