vue實現(xiàn)移動端input上傳視頻、音頻
vue移動端input上傳視頻、音頻,供大家參考,具體內(nèi)容如下
html部分
<div class="title">現(xiàn)場視頻</div> <div class="upLoad"> <label for="pop_video" id="labelr"> <video id="videoId" controls width="100%"></video> <input style="display:none;" id="pop_video" type="file" accept="video/*" capture="camcorder" v-on:change="getVideo(event, '2')" name="fileTrans" ref="file" value=""> <div class="inputVideo">上傳視頻</div> </label> </div> <div class="title">現(xiàn)場音頻頻</div> <div class="upLoad"> <label for="pop_audio" id="labelr"> <audio id="audioId" controls width="100%"></audio> <input style="display:none;" id="pop_audio" type="file" accept="audio/*" capture="camcorder" v-on:change="getAudio(event, '2')" name="fileTrans" ref="file" value=""> <div class="inputAudio">上傳音頻</div> </label> </div>
js部分
getVideo (ev, typer) {
let taht = this
//獲取上傳文件標簽
let filesId = document.getElementById('pop_video');
//獲取音頻標簽
let videoId = document.getElementById('videoId')
//把當前files[0]傳給getFileURL方法, getFileURL方法對其做一處理
let url = this.getFileURL(filesId.files[0])
if (url) {
//給video標簽設置src
videoId.src = url
}
let formData = new FormData();
formData.append("file", filesId.files[0]);
upload(this.token, formData).then(res => {
console.log(res)
if (res.data.code === 0) {
this.videoURL = res.data.data.url
}
})
console.log(url)
},
getAudio (ev, typer) {
let taht = this
//獲取上傳文件標簽
let filesId = document.getElementById('pop_audio');
//獲取音頻標簽
let audioId = document.getElementById('audioId')
//把當前files[0]傳給getFileURL方法, getFileURL方法對其做一處理
let url = this.getFileURL(filesId.files[0])
if (url) {
//給video標簽設置src
audioId.src = url
}
let formData = new FormData();
formData.append("file", filesId.files[0]);
upload(this.token, formData).then(res => {
console.log(res)
if (res.data.code === 0) {
this.audioURL = res.data.data.url
}
})
console.log(url)
},
getFileURL (file) {
let getUrl = null
if (window.createObjectURL != undefined) {
//basic
getUrl = window.createObjectURL(file)
} else if (window.URL != undefined) {//window.URL 標準定義
//mozilla(firefox)
//獲取一個http格式的url路徑,這個時候就可以設置<img>中的顯示
getUrl = window.URL.createObjectURL(file)
} else if (window.webkitURL != undefined) {//window.webkitURL是webkit的內(nèi)核
//webkit or chrome
getUrl = window.webkitURL.createObjectURL(file)
}
return getUrl
//video 標簽的 duration屬性,獲取當前視頻的長度
// let duration = videoId.duration
// if (Math.floor(duration) > 60) {
// that.layer.msg('視頻不能大于60秒')
// }
},
css部分
#inspect .upLoad {
background-color:#fff;
/* height: 1.5rem; */
text-align: left;
padding: 0.3rem;
}
#inspect .inputVideo {
background-color: #00cc66;
color: #fff;
font-size: 0.32rem;
width: 30%;
height: 0.8rem;
line-height: 0.8rem;
border-radius: 0.4rem;
text-align: center;
margin: 0 auto;
}
#inspect .inputAudio {
background-color: #5cadff;
color: #fff;
font-size: 0.32rem;
width: 30%;
height: 0.8rem;
line-height: 0.8rem;
border-radius: 0.4rem;
text-align: center;
margin: 0 auto;
}
效果圖

關(guān)于vue.js組件的教程,請大家點擊專題vue.js組件學習教程進行學習。
更多vue學習教程請閱讀專題《vue實戰(zhàn)教程》
更多精彩內(nèi)容請參考專題《ajax上傳技術(shù)匯總》,《javascript文件上傳操作匯總》和《jQuery上傳操作匯總》進行學習。
以上就是本文的全部內(nèi)容,希望對大家的學習有所幫助,也希望大家多多支持腳本之家。
相關(guān)文章
Vue判斷數(shù)組內(nèi)是否存在某一項的兩種方法
這篇文章主要介紹了Vue判斷數(shù)組內(nèi)是否存在某一項,今天給大家分享兩種方法,分別是findIndex()和 indexOf()方法,本文結(jié)合實例代碼給大家介紹的非常詳細,需要的朋友可以參考下2023-07-07
Vue.js中輕松解決v-for執(zhí)行出錯的三個方案
v-for標簽可以用來遍歷數(shù)組,將數(shù)組的每一個值綁定到相應的視圖元素中去,下面這篇文章主要給大家介紹了關(guān)于在Vue.js中輕松解決v-for執(zhí)行出錯的三個方案,文中通過示例代碼介紹的非常詳細,對大家具有一定的參考學習價值,需要的朋友們下面來一起看看吧。2017-06-06
vue3配置全局參數(shù)(掛載全局方法)以及組件的使用
這篇文章主要介紹了vue3配置全局參數(shù)(掛載全局方法)以及組件的使用方式,具有很好的參考價值,希望對大家有所幫助。如有錯誤或未考慮完全的地方,望不吝賜教2022-07-07
如何在Vue和Spring?boot之間實現(xiàn)前后端連接
最近搭建一個Springboot+vue前后端分離項目,真的很簡單,下面這篇文章主要給大家介紹了關(guān)于如何在Vue和Spring?boot之間實現(xiàn)前后端連接的相關(guān)資料,文中通過實例代碼介紹的非常詳細,需要的朋友可以參考下2023-05-05
vue中beforeRouteLeave實現(xiàn)頁面回退不刷新的示例代碼
這篇文章主要介紹了vue中beforeRouteLeave實現(xiàn)頁面回退不刷新的示例代碼,文中通過示例代碼介紹的非常詳細,對大家的學習或者工作具有一定的參考學習價值,需要的朋友們下面隨著小編來一起學習學習吧2019-11-11

