【发布时间】:2018-05-18 21:49:53
【问题描述】:
请,下面是我的 vue 组件脚本部分中的代码。
我的所有输入字段都正确,但上传的图片和视频显示为空值。
我已尝试解决此问题,但无济于事。
playVideo(url) {
let video = $('#video-preview').get(0);
video.preload = 'metadata';
// Load video in Safari / IE11
if (url) {
video.muted = false;
video.playsInline = true;
video.play();
}
},
// Read a file input as a data URL.
readDataUrl(input, callback) {
if (input.files && input.files[0]) {
let fileReader = new FileReader();
fileReader.onload = function () {
callback(fileReader.result);
};
fileReader.readAsDataURL(input.files[0]);
}
else {
callback(null);
}
},
// Read a file input as an object url.
readObjectUrl(input, callback) {
if (input.files && input.files[0]) {
let fileReader = new FileReader();
fileReader.onload = function () {
let blob = new Blob([fileReader.result], {type: input.files[0].type});
let url = URL.createObjectURL(blob);
callback(url, blob);
};
fileReader.readAsArrayBuffer(input.files[0]);
}
else {
callback(null);
}
},
}
}
我真正想要实现的是上传图像和视频文件,在保存为 blob 之前预览它们。
上图显示了我的回复@samayo
图像和视频 blob 显示为空值。
【问题讨论】:
-
您要上传到哪个 URL?是 put/post 请求吗?
-
我正在使用:submit() { let data = new FormData; data.append('description', this.description); data.append('displays', this.boards); data.append('messages', JSON.stringify(this.messages)); /*for(let property in this.messages) { data.append('messages', JSON.stringify(this.messages[property])); }*/ axios.post('/campaign', data).then(response => { this.feedback = response.data; }).catch(response.data); }
标签: javascript laravel vue.js