vue實(shí)現(xiàn)移動(dòng)端input上傳視頻、音頻
vue移動(dòng)端input上傳視頻、音頻,供大家參考,具體內(nèi)容如下
html部分
<div class="title">現(xiàn)場(chǎng)視頻</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)場(chǎng)音頻頻</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
//獲取上傳文件標(biāo)簽
let filesId = document.getElementById('pop_video');
//獲取音頻標(biāo)簽
let videoId = document.getElementById('videoId')
//把當(dāng)前files[0]傳給getFileURL方法, getFileURL方法對(duì)其做一處理
let url = this.getFileURL(filesId.files[0])
if (url) {
//給video標(biāo)簽設(shè)置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
//獲取上傳文件標(biāo)簽
let filesId = document.getElementById('pop_audio');
//獲取音頻標(biāo)簽
let audioId = document.getElementById('audioId')
//把當(dāng)前files[0]傳給getFileURL方法, getFileURL方法對(duì)其做一處理
let url = this.getFileURL(filesId.files[0])
if (url) {
//給video標(biāo)簽設(shè)置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 標(biāo)準(zhǔn)定義
//mozilla(firefox)
//獲取一個(gè)http格式的url路徑,這個(gè)時(shí)候就可以設(shè)置<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 標(biāo)簽的 duration屬性,獲取當(dāng)前視頻的長(zhǎng)度
// 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組件的教程,請(qǐng)大家點(diǎn)擊專(zhuān)題vue.js組件學(xué)習(xí)教程進(jìn)行學(xué)習(xí)。
更多vue學(xué)習(xí)教程請(qǐng)閱讀專(zhuān)題《vue實(shí)戰(zhàn)教程》
更多精彩內(nèi)容請(qǐng)參考專(zhuān)題《ajax上傳技術(shù)匯總》,《javascript文件上傳操作匯總》和《jQuery上傳操作匯總》進(jìn)行學(xué)習(xí)。
以上就是本文的全部?jī)?nèi)容,希望對(duì)大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。
相關(guān)文章
vue使用CSS插件scss時(shí)代碼報(bào)紅問(wèn)題
這篇文章主要介紹了vue使用CSS插件scss時(shí)代碼報(bào)紅問(wèn)題,具有很好的參考價(jià)值,希望對(duì)大家有所幫助,如有錯(cuò)誤或未考慮完全的地方,望不吝賜教2024-07-07
Vue判斷數(shù)組內(nèi)是否存在某一項(xiàng)的兩種方法
這篇文章主要介紹了Vue判斷數(shù)組內(nèi)是否存在某一項(xiàng),今天給大家分享兩種方法,分別是findIndex()和 indexOf()方法,本文結(jié)合實(shí)例代碼給大家介紹的非常詳細(xì),需要的朋友可以參考下2023-07-07
Vue.js中輕松解決v-for執(zhí)行出錯(cuò)的三個(gè)方案
v-for標(biāo)簽可以用來(lái)遍歷數(shù)組,將數(shù)組的每一個(gè)值綁定到相應(yīng)的視圖元素中去,下面這篇文章主要給大家介紹了關(guān)于在Vue.js中輕松解決v-for執(zhí)行出錯(cuò)的三個(gè)方案,文中通過(guò)示例代碼介紹的非常詳細(xì),對(duì)大家具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面來(lái)一起看看吧。2017-06-06
vue3配置全局參數(shù)(掛載全局方法)以及組件的使用
這篇文章主要介紹了vue3配置全局參數(shù)(掛載全局方法)以及組件的使用方式,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。如有錯(cuò)誤或未考慮完全的地方,望不吝賜教2022-07-07
如何在Vue和Spring?boot之間實(shí)現(xiàn)前后端連接
最近搭建一個(gè)Springboot+vue前后端分離項(xiàng)目,真的很簡(jiǎn)單,下面這篇文章主要給大家介紹了關(guān)于如何在Vue和Spring?boot之間實(shí)現(xiàn)前后端連接的相關(guān)資料,文中通過(guò)實(shí)例代碼介紹的非常詳細(xì),需要的朋友可以參考下2023-05-05
vue中beforeRouteLeave實(shí)現(xiàn)頁(yè)面回退不刷新的示例代碼
這篇文章主要介紹了vue中beforeRouteLeave實(shí)現(xiàn)頁(yè)面回退不刷新的示例代碼,文中通過(guò)示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來(lái)一起學(xué)習(xí)學(xué)習(xí)吧2019-11-11

