Vue觸發(fā)input選取文件點(diǎn)擊事件操作
CSS
.upload-btn-box { margin-bottom: 10px; button { margin-right: 10px; } input[type=file] { display: none; }}
HTML
<div class='upload-btn-box'><Button @click='choiceImg' icon='ios-cloud-upload-outline' type='primary'>點(diǎn)擊上傳</Button> <input ref='filElem' type='file' @change='getFile'></div>
Script
choiceImg(){ this.$refs.filElem.dispatchEvent(new MouseEvent(’click’)) },getFile(){ var that = this; const inputFile = this.$refs.filElem.files[0]; if(inputFile){if(inputFile.type !== ’image/jpeg’ && inputFile.type !== ’image/png’ && inputFile.type !== ’image/gif’){ alert(’不是有效的圖片文件!’); return;}this.imgInfo = Object.assign({}, this.imgInfo, { name: inputFile.name, size: inputFile.size, lastModifiedDate: inputFile.lastModifiedDate.toLocaleString()})const reader = new FileReader();reader.readAsDataURL(inputFile);reader.onload = function (e) { that.imgSrc = this.result;} } else {return; } }
補(bǔ)充知識(shí): vue下打包時(shí)幾個(gè)文件選擇文件打包一起 并做懶加載
直接上代碼
const DeviceManage = r => require.ensure([], () => r(require(deviceManagePath + ’main/DeviceManage’)), ’g-DeviceManage’);const SingleDeviceSet = r => require.ensure([], () => r(require(deviceManagePath + ’deviceSet/SingleDeviceSet’)), ’g-DeviceManage’);const ModifyNo = r => require.ensure([], () => r(require(deviceManagePath + ’modifyNo/ModifyNo’)), ’g-DeviceManage’);const PricePerTime = r => require.ensure([], () => r(require(deviceManagePath + ’pricePerTime/PricePerTime’)), ’g-DeviceManage’);const SetParams = r => require.ensure([], () => r(require(deviceManagePath + ’setParams/SetParams’)), ’g-DeviceManage’);const ShowDevicePrice = r => require.ensure([], () => r(require(deviceManagePath + ’showDevicePrice/ShowDevicePrice’)), ’g-DeviceManage’);const parameterSetting = r => require.ensure([], () => r(require(deviceManagePath + ’parameterSetting/parameterSetting’)), ’g-DeviceManage’);const SetParams3G = r => require.ensure([], () => r(require(deviceManagePath + ’setParams3G/SetParams3G’)), ’g-Device3Gparams’);
這么寫 所有g(shù)-DeviceManage的文件會(huì)被打包在一起
以上這篇Vue觸發(fā)input選取文件點(diǎn)擊事件操作就是小編分享給大家的全部?jī)?nèi)容了,希望能給大家一個(gè)參考,也希望大家多多支持好吧啦網(wǎng)。
相關(guān)文章:
1. 利用promise及參數(shù)解構(gòu)封裝ajax請(qǐng)求的方法2. Nginx+php配置文件及原理解析3. windows服務(wù)器使用IIS時(shí)thinkphp搜索中文無效問題4. .NET中l(wèi)ambda表達(dá)式合并問題及解決方法5. JSP數(shù)據(jù)交互實(shí)現(xiàn)過程解析6. 淺談python出錯(cuò)時(shí)traceback的解讀7. python matplotlib:plt.scatter() 大小和顏色參數(shù)詳解8. Ajax實(shí)現(xiàn)表格中信息不刷新頁面進(jìn)行更新數(shù)據(jù)9. Python importlib動(dòng)態(tài)導(dǎo)入模塊實(shí)現(xiàn)代碼10. ASP 信息提示函數(shù)并作返回或者轉(zhuǎn)向
