久久r热视频,国产午夜精品一区二区三区视频,亚洲精品自拍偷拍,欧美日韩精品二区

您的位置:首頁技術文章
文章詳情頁

Vue觸發input選取文件點擊事件操作

瀏覽:97日期:2022-12-12 18:43:27

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'>點擊上傳</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; } }

補充知識: vue下打包時幾個文件選擇文件打包一起 并做懶加載

直接上代碼

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-DeviceManage的文件會被打包在一起

以上這篇Vue觸發input選取文件點擊事件操作就是小編分享給大家的全部內容了,希望能給大家一個參考,也希望大家多多支持好吧啦網。

標簽: Vue
相關文章:
主站蜘蛛池模板: 日土县| 葫芦岛市| 洪雅县| 化隆| 汉寿县| 佛教| 五家渠市| 孟州市| 定边县| 德昌县| 黑水县| 洛川县| 桃江县| 新乐市| 金昌市| 西充县| 左云县| 易门县| 兖州市| 扶余县| 新宾| 莫力| 沽源县| 胶州市| 吴旗县| 房产| 新昌县| 湛江市| 贵州省| 阿克陶县| 拜城县| 西青区| 尼玛县| 舟曲县| 景谷| 河西区| 永靖县| 古丈县| 金华市| 黔西县| 即墨市|