<div v-for="item in videoData" :key="item.kshv_id"
:id="item.kshv_id" v-loading="loading">
data声明为videoData:[],
获取请求后赋值
this.videoData = res.data.info.list;
this.videoSRC(res.data.info.list);
videoSRC(list){
for(var i=0;i<list.length;i++){
this.videoAjax(list[i]);
}
},
videoAjax(item){
axios.post(xxx'/xxx',
{
传参
},{
responseType: 'blob'
},{
withCredentials: true
}).then((res)=>{
var html = "<video autoplay='true' height='100%' width='100%' controls='controls' loop='true' src='"+window.URL.createObjectURL(new Blob([res.data]))+"' ></video> ";
document.getElementById(item.kshv_id).innerHTML = html;
this.loading = false;
}).catch(function (response) {
console.log(response);
});
},
后端
import org.apache.commons.io.FileUtils;
@PostMapping("/xxx")
public ResponseEntity<byte[]> previewVideoONE(@RequestBody Map<String,Object> map, HttpServletResponse response) throws Exception {
String token = (String) mapa.get("token");
try {
ResponseEntity<byte[]> responseEntity = null;
Map<String,Object> mp = new HashMap<>();
String path = mapa.get("url").toString();
HttpHeaders headers = new HttpHeaders();
headers.setContentType(MediaType.APPLICATION_OCTET_STREAM);
headers.setContentDispositionFormData("attachment", path);
responseEntity = new ResponseEntity<byte[]>(FileUtils.readFileToByteArray(new File(path)), headers, HttpStatus.CREATED);
return responseEntity;
} catch (IOException e) {
e.printStackTrace();
return null;
}
}
url字段处理
map.get("video_url").toString().replace("\\","//")+"'